<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET MVC</title><link>http://forums.asp.net/1146.aspx</link><description>Discussions regarding Model-View-Controller (MVC) support in ASP.NET.  &lt;a href="http://forums.asp.net/1215.aspx"&gt;T4MVC subforum&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3275120.aspx</link><pubDate>Sun, 05 Jul 2009 05:30:20 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3275120</guid><dc:creator>zielony</dc:creator><author>zielony</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3275120.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3275120</wfw:commentRss><description>&lt;p&gt;English isn&amp;#39;t my national language so as I understand - SetModelValue is used to return old values when form had errors. But I have:&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;ViewData[&lt;/span&gt;&lt;span&gt;&amp;quot;id_author&amp;quot;&lt;/span&gt;&lt;span&gt;]&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span&gt;new&lt;/span&gt;&lt;span&gt;&amp;nbsp;MultiSelectList(b.TakeAuthors(),&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;quot;idAuthor&amp;quot;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;quot;author&amp;quot;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;b&gt;Request.Form[&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;span&gt;&amp;quot;id_author&amp;quot;&lt;/span&gt;&lt;/b&gt;&lt;span&gt;&lt;b&gt;]&lt;/b&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;thx 4. argument in MultiSelectList I return to ListBox old selected values so I still don&amp;#39;t understand &lt;/span&gt;&lt;/span&gt;ModelState.SetModelValue in that case - I must have ModelState.SetModelValue but it does nothing.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3274947.aspx</link><pubDate>Sat, 04 Jul 2009 20:20:50 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274947</guid><dc:creator>levib</dc:creator><author>levib</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274947.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274947</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;zielony:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;I don&amp;#39;t know who and why has &amp;quot;invented&amp;quot; that but I think THIS IS VERY STUPID !!&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;See &lt;a href="http://forums.asp.net/p/1377232/2908610.aspx"&gt;this post&lt;/a&gt; for the context around these two methods.&amp;nbsp; Also, if you would like the help of the product team and others in these forums, it wouldn&amp;#39;t hurt to be a bit more professional in your demeanor. :)&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3274702.aspx</link><pubDate>Sat, 04 Jul 2009 13:34:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274702</guid><dc:creator>zielony</dc:creator><author>zielony</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274702.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274702</wfw:commentRss><description>&lt;p&gt;PEOPLE I HAVE A SOLUTION for mine ListBox!!!!!!!!!!!!&lt;/p&gt;&lt;p&gt;I had to add:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;ModelState.SetModelValue(&amp;quot;id_author&amp;quot;, new ValueProviderResult(null, &amp;quot;&amp;quot;, null));&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre name="code" class="c-sharp"&gt;ViewData[&amp;quot;id_author&amp;quot;] = new MultiSelectList(b.TakeAuthors(), &amp;quot;idAuthor&amp;quot;, &amp;quot;author&amp;quot;, Request.Form[&amp;quot;id_author&amp;quot;]);&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="c-sharp"&gt;if (Request.Form[&amp;quot;id_author&amp;quot;] == null)
            {
                ModelState.AddModelError(&amp;quot;id_author&amp;quot;, &amp;quot;You must choose authors.&amp;quot;);
                ModelState.SetModelValue(&amp;quot;id_author&amp;quot;, new ValueProviderResult(null, &amp;quot;&amp;quot;, null));
            }   &lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;I don&amp;#39;t know who and why has &amp;quot;invented&amp;quot; that but I think THIS IS VERY STUPID !!&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3274328.aspx</link><pubDate>Sat, 04 Jul 2009 06:24:10 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274328</guid><dc:creator>zielony</dc:creator><author>zielony</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274328.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274328</wfw:commentRss><description>&lt;p&gt;As I understand second parameter is string with id selected authors for example: &amp;quot;1,5&amp;quot; yes ?&lt;/p&gt;&lt;p&gt;What about first parameter ? I don&amp;#39;t understand&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3273904.aspx</link><pubDate>Fri, 03 Jul 2009 18:27:47 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273904</guid><dc:creator>bitmask</dc:creator><author>bitmask</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273904.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3273904</wfw:commentRss><description>&lt;p&gt;The ValueProvider represents a collection of name/value pairs that are present somewhere in the request. It puts together all the name/value pairs from posted form values, the query string, and routing data (plus, adds some relavent culture information to each). &lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t have an id_author selected, then you won&amp;#39;t have an id_author in the Request.Form collection, and it won&amp;#39;t be in the ValueProvider either (unless you have it in the query string or in the routing data). Your code is passing a null value to SetModelValue, which is going to make other parts of the framework unhappy. &lt;/p&gt;
&lt;p&gt;The quickest hack would be to pass in a ValueProviderResult for id_author with empty strings, but in the long run I&amp;#39;d look at the model binding examples so you can encapsulate all this work. &lt;/p&gt;</description></item><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3273725.aspx</link><pubDate>Fri, 03 Jul 2009 15:00:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273725</guid><dc:creator>zielony</dc:creator><author>zielony</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273725.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3273725</wfw:commentRss><description>&lt;p&gt;No answers ? As I thought - nobody understand this STUPID ValueProvider :/ I don&amp;#39;t know what I should do now. :(&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3273109.aspx</link><pubDate>Fri, 03 Jul 2009 08:57:25 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273109</guid><dc:creator>zielony</dc:creator><author>zielony</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273109.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3273109</wfw:commentRss><description>&lt;p&gt;hm...... What do you mean ? I don&amp;#39;t understand &lt;span&gt;&lt;span&gt;ValueProvider so I copied and pasted inside him name of &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;Html.ListBox: &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;ValueProvide[&amp;quot; here_I_copied_name &amp;quot;]&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;. Did I do it wrong ? :D So how should it look like ?&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span&gt;PS. In Symfony framework + php + Doctrine wasn&amp;#39;t so complicated things like &lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;ValueProvider :P&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Re: Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3273086.aspx</link><pubDate>Fri, 03 Jul 2009 08:46:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273086</guid><dc:creator>levib</dc:creator><author>levib</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273086.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3273086</wfw:commentRss><description>&lt;p&gt;Are you sure &lt;span&gt;&lt;span&gt;ValueProvider[&lt;/span&gt;&lt;span&gt;&amp;quot;id_author&amp;quot;&lt;/span&gt;&lt;span&gt;] is not null?&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Object reference not set to an instance of an object. ModelState.SetModelValue - BUG ??</title><link>http://forums.asp.net/thread/3272817.aspx</link><pubDate>Fri, 03 Jul 2009 06:30:53 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3272817</guid><dc:creator>zielony</dc:creator><author>zielony</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3272817.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3272817</wfw:commentRss><description>&lt;p&gt;I have in controller:&lt;/p&gt;&lt;pre name="code" class="c-sharp"&gt;[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude = &amp;quot;id_book&amp;quot;)] books bok)
        {
            Books b = new Books();
            ViewData[&amp;quot;id_author&amp;quot;] = new MultiSelectList(b.TakeAuthors(), &amp;quot;idAuthor&amp;quot;, &amp;quot;author&amp;quot;);
            
           
            if (Request.Form[&amp;quot;id_author&amp;quot;] == null || Request.Form[&amp;quot;id_author&amp;quot;].Trim().Length == 0)
            {
                ModelState.AddModelError(&amp;quot;id_author&amp;quot;, &amp;quot;You must choose authors.&amp;quot;);
                ModelState.SetModelValue(&amp;quot;id_author&amp;quot;, ValueProvider[&amp;quot;id_author&amp;quot;]);                
            }
            if (!ModelState.IsValid)
            {
                return View(bok);
            } 

}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;In view:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;&amp;lt;%= Html.ListBox(&amp;quot;id_author&amp;quot;, null, new { size = 5 })%&amp;gt;
&amp;lt;%= Html.ValidationMessage(&amp;quot;id_author&amp;quot;, &amp;quot;*&amp;quot;) %&amp;gt;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;And when I don&amp;#39;t choose author I have an error:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Object reference not set to an instance of an object.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;I have found article about that:&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.crankingoutcode.com/?aspxerrorpath=/2009/02/01/IssuesWithAddModelErrorSetModelValueWithMVCRC1.aspx"&gt;http://www.crankingoutcode.com/?aspxerrorpath=/2009/02/01/IssuesWithAddModelErrorSetModelValueWithMVCRC1.aspx&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;But in my case ModelState.SetModelValue doesn&amp;#39;t work so I think it can be bug ? Am I right ?&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>