Model biding sucks!http://forums.asp.net/t/1800977.aspx/1?Model+biding+sucks+Mon, 07 May 2012 15:11:08 -040018009774969054http://forums.asp.net/p/1800977/4969054.aspx/1?Model+biding+sucks+Model biding sucks! <p>MVC modelbiding is not working anymore. i spent alot of time trying to post some json object to my server.&nbsp;</p> <p>mvc class: Menu</p> <p>public class menu&nbsp;</p> <p>{</p> <p>public string name {get;set;}</p> <p>}</p> <p>my javascript on the browser which sends json to server using ajax.&nbsp;</p> <pre class="prettyprint">request.send(JSON.stringify({ name: this.dataset.name }));</pre> <p>when i was debugging, i checked the value of "this.dataset.name", it's value is "one". and on server when i hit the break point at controller which recieves menu object, is not recieving menu object. here is the code.&nbsp;</p> <pre class="prettyprint"> public ActionResult getcontent(menu m) { viewmodelsub vms = new viewmodelsub(); vms.n = db.navimenus.Where(r =&gt; r.menuname == m.name).ToList(); vms.p = db.posts.Where(r =&gt; r.navname ==vms.n.FirstOrDefault().navname).ToList(); return Json(vms) ; } </pre> <p><br> Can anyone please help me with this?</p> <p></p> 2012-05-07T12:21:34-04:004969072http://forums.asp.net/p/1800977/4969072.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>1.&nbsp; </p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> when i hit the break point at controller which recieves menu object, is not recieving menu object.</blockquote> <p></p> <p>Put the breakpoint at </p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> viewmodelsub vms = new viewmodelsub();</blockquote> <p></p> <p></p> <p>2. </p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> MVC modelbiding is not working anymore</blockquote> <p></p> <p>Does your example work on other time?&nbsp; Or it does not work from the beginning?</p> <p>3. </p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> Model biding sucks!</blockquote> <p></p> <p>Maybe </p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> request.send </blockquote> sucks. What framework are you using for ajax requests? <p></p> <p>Please see my example of http://bit.ly/mvc_ajax_jquery - it works and more, gives indication about where is the error - on server or on communication side.</p> <p></p> <p></p> <p></p> 2012-05-07T12:29:17-04:004969077http://forums.asp.net/p/1800977/4969077.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>try json as below</p> <pre class="prettyprint">{'Menu':{'name':this.dataset.name}}</pre> <p>Hope it helps!<br> <br> </p> 2012-05-07T12:32:21-04:004969146http://forums.asp.net/p/1800977/4969146.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>what is &quot;request.send&quot;. Are you not using the jquery ajax functions? I suggest to use jQuery to avoid compatibility problems.</p> <p>Are you sending a post or a get? Because if you are sending a get...this might be a routing parameters problem</p> 2012-05-07T12:58:33-04:004969208http://forums.asp.net/p/1800977/4969208.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>also is you request.send setting the content type to application/json?</p> <p>use fiddler to monitor the requests and responses to see if you are sending valid posts.</p> 2012-05-07T13:35:13-04:004969244http://forums.asp.net/p/1800977/4969244.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>@bruce</p> <p>yeah, i'm setting the content type to &quot;application/json&quot;. here is all my code when an event click on an element is triggered.&nbsp;</p> <pre class="prettyprint">function menuclicked() { var request = new XMLHttpRequest(); request.open(&quot;GET&quot;, 'jd/getcontent'); // Specify URL to fetch request.setRequestHeader(&quot;Content-Type&quot;, &quot;application/json&quot;); request.onreadystatechange = function () { if (request.readyState === 4 &amp;&amp; request.status === 200) { alert((JSON.parse(request.responseText))); } else if (request.readyState === 4 &amp;&amp; request.status !== 200) alert('error'); };</pre> <pre class="prettyprint"> request.send(JSON.stringify({ name: this.dataset.name })); }</pre> <p>Still i'm having this same problem !</p> <p>thanks for your reply~!</p> 2012-05-07T14:02:57-04:004969246http://forums.asp.net/p/1800977/4969246.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>@gopakumar</p> <p>that didnt work out !&nbsp;</p> <p>anyway thanks.</p> 2012-05-07T14:03:43-04:004969254http://forums.asp.net/p/1800977/4969254.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>1. i dont think putting the break point in a different solution solves this problem in this situation. even though i tried but .....</p> <p>2. this process did work before. now i'm working on another web site now it's having this problem.</p> <p>3. haha ,&nbsp;</p> <p>'Request.send&quot; doesnt suck. it's a built in javascript method in every browser. i debugged this code using fiddler and IE developer tools. and it's infact sending the server a json object.&nbsp;</p> <p>4. i don't use somebody's framework for my website. &nbsp;</p> 2012-05-07T14:08:20-04:004969294http://forums.asp.net/p/1800977/4969294.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p></p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> i dont think putting the break point in a different solution solves this problem in this situation. even though i tried but </blockquote> <p></p> <p>I did not tell to put in another solution. Do you have more than one?</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> 2. this process did work before. now i'm working on another web site now it's having this problem.</blockquote> <p></p> <p>Maybe you did not add all js references.</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> 'Request.send&quot; doesnt suck. it's a built in javascript method in every browser.</blockquote> <p></p> <p>Please provide reference about this javascript function . I did not found.( and it is in <cite><b>lynx</b>.<b>browser</b>.org</cite>&nbsp; too? Also in IE 5 ? Netscape 1.0 ?)</p> <p>Later Edit: Now I see that your request is , in fact, <span class="typ">XMLHttpRequest</span><span class="pun">()</span> .&nbsp; And you do use GET , not POST&nbsp; - and, usually, GET is denied on ajax requests for MVC ( can be changed).&nbsp; And what version of IE are you using? </p> <pre class="prettyprint"></pre> <p></p> 2012-05-07T14:26:18-04:004969296http://forums.asp.net/p/1800977/4969296.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p></p> <blockquote><span class="icon-blockquote"></span> <h4>sean freeman</h4> <p></p> <pre class="prettyprint">request.open(&quot;GET&quot;, 'jd/getcontent')</pre> <p></p> </blockquote> <p></p> <p>PLease use POST.</p> 2012-05-07T14:26:52-04:004969313http://forums.asp.net/p/1800977/4969313.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>Thre you go!</p> <p>yeah, it was actually POST, not GET. thats why it worked before. i'm sorry for that,&nbsp;</p> <p>Model Binding doesn't suck anymore!</p> <p>it's just my mistake.&nbsp;</p> <p>Thank you all for you replies. i really appreciate it.&nbsp;</p> 2012-05-07T14:37:17-04:004969369http://forums.asp.net/p/1800977/4969369.aspx/1?Re+Model+biding+sucks+Re: Model biding sucks! <p>Moral of the story:<br> If it works first time, and second time not, spot the differences - do not accuse something tested by other developers.</p> 2012-05-07T15:11:08-04:00