MVC3 RC2 JSON Post 绑定无法正常工作
我看过有关此主题的其他帖子,并尝试过各种变体,但仍然无法使 JSON 模型绑定正常工作。
我的 global.asax.cs Application_Start 方法中有以下内容:
ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
回发数据如下所示:
{"UserName":"Mike","Password":"password","Persist":true}
我的 PoCo:
public class UserLoginViewModel {
public string UserName { get; set; }
public string Password { get; set; }
public bool Persist { get; set; }
}
控制器方法正常触发,但具有默认的 UserLoginViewModel 对象,其中 UserName = null、Password = null 和 Persist = false;签名看起来像这样:
[HttpPost]
public ActionResult Logon(UserLoginViewModel model) {
if (ModelState.IsValid) {
...
I've seen other posts on this subject and have fiddled with variations but still cannot not get the JSON model binding to work correctly.
I have the following in my global.asax.cs Application_Start method:
ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
The post back data looks like this:
{"UserName":"Mike","Password":"password","Persist":true}
My PoCo:
public class UserLoginViewModel {
public string UserName { get; set; }
public string Password { get; set; }
public bool Persist { get; set; }
}
The controller method fires properly but has default UserLoginViewModel object with UserName = null, Password = null, and Persist = false; the signature looks like this:
[HttpPost]
public ActionResult Logon(UserLoginViewModel model) {
if (ModelState.IsValid) {
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在客户端!我没有设置 contentType。
The problem is on the client side! I didn't have the contentType set.