<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ASP.NET MVC &#8211; Using Controller.UpdateModel when using a ViewModel</title>
	<atom:link href="http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/</link>
	<description>Everything .NET and C#</description>
	<lastBuildDate>Tue, 31 Aug 2010 03:59:09 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Sada</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-2894</link>
		<dc:creator>Sada</dc:creator>
		<pubDate>Wed, 18 Aug 2010 18:33:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-2894</guid>
		<description>Thank you very much!!!</description>
		<content:encoded><![CDATA[<p>Thank you very much!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Conor</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-2554</link>
		<dc:creator>Conor</dc:creator>
		<pubDate>Tue, 03 Aug 2010 23:23:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-2554</guid>
		<description>This article was well organized and extremely helpful. Thanks!</description>
		<content:encoded><![CDATA[<p>This article was well organized and extremely helpful. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Area080</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-2143</link>
		<dc:creator>Area080</dc:creator>
		<pubDate>Fri, 09 Jul 2010 13:15:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-2143</guid>
		<description>Thanks, Helped a lot</description>
		<content:encoded><![CDATA[<p>Thanks, Helped a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ana</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-2003</link>
		<dc:creator>Ana</dc:creator>
		<pubDate>Tue, 15 Jun 2010 13:35:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-2003</guid>
		<description>Hi! That&#039;s what I&#039;ve been looking for! Finaly, after 30+ google and baidu searching, this article hit the spot. Thanks a lot.</description>
		<content:encoded><![CDATA[<p>Hi! That&#8217;s what I&#8217;ve been looking for! Finaly, after 30+ google and baidu searching, this article hit the spot. Thanks a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: British Developer</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1923</link>
		<dc:creator>British Developer</dc:creator>
		<pubDate>Mon, 07 Jun 2010 14:50:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1923</guid>
		<description>Great! Helped me a lot as it seems to be strangely undocumented anyway! Thanks</description>
		<content:encoded><![CDATA[<p>Great! Helped me a lot as it seems to be strangely undocumented anyway! Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1804</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Thu, 20 May 2010 14:30:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1804</guid>
		<description>Thanks!  Ran into this and have been looking for the obvious solution.  Sad the examples don&#039;t show this...</description>
		<content:encoded><![CDATA[<p>Thanks!  Ran into this and have been looking for the obvious solution.  Sad the examples don&#8217;t show this&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: (david, "newb")</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1771</link>
		<dc:creator>(david, "newb")</dc:creator>
		<pubDate>Fri, 14 May 2010 06:19:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1771</guid>
		<description>Add one more to the thanks pile!

Thanks...very useful blog</description>
		<content:encoded><![CDATA[<p>Add one more to the thanks pile!</p>
<p>Thanks&#8230;very useful blog</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1729</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Thu, 06 May 2010 06:53:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1729</guid>
		<description>Glad it helped. It had me stumped for a while.</description>
		<content:encoded><![CDATA[<p>Glad it helped. It had me stumped for a while.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cheny</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1720</link>
		<dc:creator>Cheny</dc:creator>
		<pubDate>Wed, 05 May 2010 05:35:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1720</guid>
		<description>Hi! That&#039;s what I&#039;ve been looking for! Finaly, after 30+ google and baidu searching, this article hit the spot. Thanks a lot.</description>
		<content:encoded><![CDATA[<p>Hi! That&#8217;s what I&#8217;ve been looking for! Finaly, after 30+ google and baidu searching, this article hit the spot. Thanks a lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Stolle</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1689</link>
		<dc:creator>Justin Stolle</dc:creator>
		<pubDate>Wed, 28 Apr 2010 22:05:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1689</guid>
		<description>Thank you for this information!!</description>
		<content:encoded><![CDATA[<p>Thank you for this information!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1484</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Wed, 14 Apr 2010 04:16:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1484</guid>
		<description>Hi Torsten

You should be able to do it in the same way. What problems are you getting?</description>
		<content:encoded><![CDATA[<p>Hi Torsten</p>
<p>You should be able to do it in the same way. What problems are you getting?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1480</link>
		<dc:creator>Joe</dc:creator>
		<pubDate>Wed, 14 Apr 2010 03:53:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1480</guid>
		<description>Hi Senthil

Glad that it helped</description>
		<content:encoded><![CDATA[<p>Hi Senthil</p>
<p>Glad that it helped</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Senthil</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1459</link>
		<dc:creator>Senthil</dc:creator>
		<pubDate>Mon, 12 Apr 2010 03:11:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1459</guid>
		<description>Hi Joe,
It was really helpful to figure out ViewModel object validation issue in one of my project. Just to add some more info for anyone struggling to update deep object tree in ViewModel object validation as below...

1. e.g view model
    
public class ProductFormViewModel
    {
        private CategoryTypeService _svcCategoryType = new CategoryTypeService();
        private CategoryService _svcCategory = new CategoryService();

        public Product ProductView{ get; set;}
        public SelectList CategoryTypes { get; set; }
        public SelectList Categories { get; set; }

        public ProductFormViewModel()
        {
            CategoryTypes = new SelectList(_svcCategoryType.GetList(), &quot;ID&quot;, &quot;Name&quot;);
            Categories = new SelectList(_svcCategory.GetList(), &quot;ID&quot;, &quot;Name&quot;, null);
        }
        public ProductFormViewModel(Product Product)
        {
            ProductView = Product;
            CategoryTypes = new SelectList(_svcCategoryType.GetList(), &quot;ID&quot;, &quot;Name&quot;, ProductView.Category.CategoryTypeID);
            Categories = new SelectList(_svcCategory.GetList(), &quot;ID&quot;, &quot;Name&quot;, ProductView.CategoryID);
        }
    }

2.Product Controller &quot;Create&quot; sample

public ActionResult Create(FormCollection formValues)
        {

            ViewData[&quot;ActionFlag&quot;] = ActionType.CREATE;
            Product entityToAdd =new Product();
            string[] excludePpty = {&quot;Category&quot; };
            UpdateModel(entityToAdd ,&quot;ProductView&quot;,null,excludePpty,formValues.ToValueProvider());
            entityToAdd.Category = _svcProduct.GetCategoryByProductCategoryID(entityToAdd.CategoryID);
            if (ModelState.IsValid)
            {
                try
                {
                    if (_svcProduct.Create(entityToAdd))
                        return RedirectToAction(&quot;Index&quot;);
                    else
                        return View(&quot;Create&quot;, new ProductFormViewModel(entityToAdd));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(&quot;General&quot;, ex);
                    return View(&quot;Create&quot;, new ProductFormViewModel(entityToAdd));
                }
            }
            else
            {
                return View(&quot;Create&quot;, new ProductFormViewModel(entityToAdd));
            }
        }
 

Thanks
Senthil</description>
		<content:encoded><![CDATA[<p>Hi Joe,<br />
It was really helpful to figure out ViewModel object validation issue in one of my project. Just to add some more info for anyone struggling to update deep object tree in ViewModel object validation as below&#8230;</p>
<p>1. e.g view model</p>
<p>public class ProductFormViewModel<br />
    {<br />
        private CategoryTypeService _svcCategoryType = new CategoryTypeService();<br />
        private CategoryService _svcCategory = new CategoryService();</p>
<p>        public Product ProductView{ get; set;}<br />
        public SelectList CategoryTypes { get; set; }<br />
        public SelectList Categories { get; set; }</p>
<p>        public ProductFormViewModel()<br />
        {<br />
            CategoryTypes = new SelectList(_svcCategoryType.GetList(), &#8220;ID&#8221;, &#8220;Name&#8221;);<br />
            Categories = new SelectList(_svcCategory.GetList(), &#8220;ID&#8221;, &#8220;Name&#8221;, null);<br />
        }<br />
        public ProductFormViewModel(Product Product)<br />
        {<br />
            ProductView = Product;<br />
            CategoryTypes = new SelectList(_svcCategoryType.GetList(), &#8220;ID&#8221;, &#8220;Name&#8221;, ProductView.Category.CategoryTypeID);<br />
            Categories = new SelectList(_svcCategory.GetList(), &#8220;ID&#8221;, &#8220;Name&#8221;, ProductView.CategoryID);<br />
        }<br />
    }</p>
<p>2.Product Controller &#8220;Create&#8221; sample</p>
<p>public ActionResult Create(FormCollection formValues)<br />
        {</p>
<p>            ViewData["ActionFlag"] = ActionType.CREATE;<br />
            Product entityToAdd =new Product();<br />
            string[] excludePpty = {&#8220;Category&#8221; };<br />
            UpdateModel(entityToAdd ,&#8221;ProductView&#8221;,null,excludePpty,formValues.ToValueProvider());<br />
            entityToAdd.Category = _svcProduct.GetCategoryByProductCategoryID(entityToAdd.CategoryID);<br />
            if (ModelState.IsValid)<br />
            {<br />
                try<br />
                {<br />
                    if (_svcProduct.Create(entityToAdd))<br />
                        return RedirectToAction(&#8220;Index&#8221;);<br />
                    else<br />
                        return View(&#8220;Create&#8221;, new ProductFormViewModel(entityToAdd));<br />
                }<br />
                catch (Exception ex)<br />
                {<br />
                    ModelState.AddModelError(&#8220;General&#8221;, ex);<br />
                    return View(&#8220;Create&#8221;, new ProductFormViewModel(entityToAdd));<br />
                }<br />
            }<br />
            else<br />
            {<br />
                return View(&#8220;Create&#8221;, new ProductFormViewModel(entityToAdd));<br />
            }<br />
        }</p>
<p>Thanks<br />
Senthil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Torsten</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1362</link>
		<dc:creator>Torsten</dc:creator>
		<pubDate>Wed, 31 Mar 2010 15:30:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1362</guid>
		<description>Hi!

very nice post... but when i&#039;ve a MultiSelectList in the ViewModel and show this list with ListBoxFor. How can i update the ViewModel with UpdateModel to get the selectet items?</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>very nice post&#8230; but when i&#8217;ve a MultiSelectList in the ViewModel and show this list with ListBoxFor. How can i update the ViewModel with UpdateModel to get the selectet items?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lesa</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1187</link>
		<dc:creator>lesa</dc:creator>
		<pubDate>Thu, 04 Mar 2010 05:26:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1187</guid>
		<description>thx.. very useful information and very timely..</description>
		<content:encoded><![CDATA[<p>thx.. very useful information and very timely..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ASP.NET MVC Archived Blog Posts, Page 1</title>
		<link>http://www.joe-stevens.com/2010/02/17/asp-net-mvc-using-controller-updatemodel-when-using-a-viewmodel/comment-page-1/#comment-1136</link>
		<dc:creator>ASP.NET MVC Archived Blog Posts, Page 1</dc:creator>
		<pubDate>Tue, 23 Feb 2010 03:24:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.joe-stevens.com/?p=443#comment-1136</guid>
		<description>[...] to VoteASP.NET MVC – Using Controller.UpdateModel when using a ViewModel ... (2/16/2010)Tuesday, February 16, 2010 from JoeWhen updating a model in MVC it is common to use the [...]</description>
		<content:encoded><![CDATA[<p>[...] to VoteASP.NET MVC – Using Controller.UpdateModel when using a ViewModel &#8230; (2/16/2010)Tuesday, February 16, 2010 from JoeWhen updating a model in MVC it is common to use the [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
