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.
public ActionResult getcontent(menu m)
{
viewmodelsub vms = new viewmodelsub();
vms.n = db.navimenus.Where(r => r.menuname == m.name).ToList();
vms.p = db.posts.Where(r => r.navname ==vms.n.FirstOrDefault().navname).ToList();
return Json(vms) ;
}
when i hit the break point at controller which recieves menu object, is not recieving menu object.
Put the breakpoint at
sean freeman
viewmodelsub vms = new viewmodelsub();
2.
sean freeman
MVC modelbiding is not working anymore
Does your example work on other time? Or it does not work from the beginning?
3.
sean freeman
Model biding sucks!
Maybe
sean freeman
request.send
sucks. What framework are you using for ajax requests?
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.
1. i dont think putting the break point in a different solution solves this problem in this situation. even though i tried but .....
2. this process did work before. now i'm working on another web site now it's having this problem.
3. haha ,
'Request.send" 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.
4. i don't use somebody's framework for my website.
i dont think putting the break point in a different solution solves this problem in this situation. even though i tried but
I did not tell to put in another solution. Do you have more than one?
sean freeman
2. this process did work before. now i'm working on another web site now it's having this problem.
Maybe you did not add all js references.
sean freeman
'Request.send" doesnt suck. it's a built in javascript method in every browser.
Please provide reference about this javascript function . I did not found.( and it is in
lynx.browser.org too? Also in IE 5 ? Netscape 1.0 ?)
Later Edit: Now I see that your request is , in fact, XMLHttpRequest() . And you do use GET , not POST - and, usually, GET is denied on ajax requests for MVC ( can be changed). And what version of IE are
you using?
sean freeman
Member
170 Points
96 Posts
Model biding sucks!
May 07, 2012 12:21 PM|LINK
MVC modelbiding is not working anymore. i spent alot of time trying to post some json object to my server.
mvc class: Menu
public class menu
{
public string name {get;set;}
}
my javascript on the browser which sends json to server using ajax.
request.send(JSON.stringify({ name: this.dataset.name }));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.
public ActionResult getcontent(menu m) { viewmodelsub vms = new viewmodelsub(); vms.n = db.navimenus.Where(r => r.menuname == m.name).ToList(); vms.p = db.posts.Where(r => r.navname ==vms.n.FirstOrDefault().navname).ToList(); return Json(vms) ; }Can anyone please help me with this?
ignatandrei
All-Star
134971 Points
21637 Posts
Moderator
MVP
Re: Model biding sucks!
May 07, 2012 12:29 PM|LINK
1.
Put the breakpoint at
2.
Does your example work on other time? Or it does not work from the beginning?
3.
Maybe
sucks. What framework are you using for ajax requests?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.
gopakumar.r
Participant
959 Points
193 Posts
Re: Model biding sucks!
May 07, 2012 12:32 PM|LINK
try json as below
{'Menu':{'name':this.dataset.name}}Hope it helps!
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Model biding sucks!
May 07, 2012 12:58 PM|LINK
what is "request.send". Are you not using the jquery ajax functions? I suggest to use jQuery to avoid compatibility problems.
Are you sending a post or a get? Because if you are sending a get...this might be a routing parameters problem
Mvc Controls Toolkit | Data Moving Plug-in Videos
bruce (sqlwo...
All-Star
36850 Points
5445 Posts
Re: Model biding sucks!
May 07, 2012 01:35 PM|LINK
also is you request.send setting the content type to application/json?
use fiddler to monitor the requests and responses to see if you are sending valid posts.
sean freeman
Member
170 Points
96 Posts
Re: Model biding sucks!
May 07, 2012 02:02 PM|LINK
@bruce
yeah, i'm setting the content type to "application/json". here is all my code when an event click on an element is triggered.
function menuclicked() { var request = new XMLHttpRequest(); request.open("GET", 'jd/getcontent'); // Specify URL to fetch request.setRequestHeader("Content-Type", "application/json"); request.onreadystatechange = function () { if (request.readyState === 4 && request.status === 200) { alert((JSON.parse(request.responseText))); } else if (request.readyState === 4 && request.status !== 200) alert('error'); };request.send(JSON.stringify({ name: this.dataset.name })); }Still i'm having this same problem !
thanks for your reply~!
sean freeman
Member
170 Points
96 Posts
Re: Model biding sucks!
May 07, 2012 02:03 PM|LINK
@gopakumar
that didnt work out !
anyway thanks.
sean freeman
Member
170 Points
96 Posts
Re: Model biding sucks!
May 07, 2012 02:08 PM|LINK
1. i dont think putting the break point in a different solution solves this problem in this situation. even though i tried but .....
2. this process did work before. now i'm working on another web site now it's having this problem.
3. haha ,
'Request.send" 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.
4. i don't use somebody's framework for my website.
ignatandrei
All-Star
134971 Points
21637 Posts
Moderator
MVP
Re: Model biding sucks!
May 07, 2012 02:26 PM|LINK
I did not tell to put in another solution. Do you have more than one?
Maybe you did not add all js references.
Please provide reference about this javascript function . I did not found.( and it is in lynx.browser.org too? Also in IE 5 ? Netscape 1.0 ?)
Later Edit: Now I see that your request is , in fact, XMLHttpRequest() . And you do use GET , not POST - and, usually, GET is denied on ajax requests for MVC ( can be changed). And what version of IE are you using?
ignatandrei
All-Star
134971 Points
21637 Posts
Moderator
MVP
Re: Model biding sucks!
May 07, 2012 02:26 PM|LINK
PLease use POST.