asp.net-mvc – MVC简单模型绑定无法正常工作
发布时间:2020-12-16 04:15:17 所属栏目:asp.Net 来源:网络整理
导读:好吧,这一定是一些愚蠢的东西,我做错了,但我找不到它. MVC行动: [AcceptVerbs(HttpVerbs.Post)]public virtual ActionResult Create(BatchCreateViewModel createModel){ return RedirectToRoute(MVC.Home.Display());} BatchCreateViewModel: public clas
好吧,这一定是一些愚蠢的东西,我做错了,但我找不到它.
MVC行动: [AcceptVerbs(HttpVerbs.Post)] public virtual ActionResult Create(BatchCreateViewModel createModel) { return RedirectToRoute(MVC.Home.Display()); } BatchCreateViewModel: public class BatchCreateViewModel { bool searchAVM; bool searchBPO; bool searchAppraisal; int transactionAge; string Description; string uploadfile; } View页面上有一些名为“searchAVM”,“searchBPO”,“searchAppraisal”的控件,(复选框)“transactionAge”(一组带整数值的单选按钮)和“description”(文本框) 当我在“Create”条目处中断时,createModel就在那里,但是具有所有默认值(对于字符串为null,对于布尔值为false,对于int为0).如果我检查Request.Form,值就在那里,但它们只是没有进入模型. 我究竟做错了什么? (这是在MVC 2,框架4下.) 解决方法
您的视图模型应具有自动属性,而不是公共变量.它之前让我感到惊讶!
所以它应该是: public class BatchCreateViewModel { public bool searchAVM {get;set;} public bool searchBPO {get;set;} public bool searchAppraisal {get;set;} public int transactionAge {get;set;} public string Description {get;set;} public string uploadfile {get;set;} } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在没有viewstate的情况下运行ASP.NET
- 关于asp.netCore3.0区域和路由配置
- 什么时候最早我可以在ASP.NET MVC页面生命周期中访问SESSIO
- asp.net-mvc – 访问ASP.NET MVC应用程序中的控制器/操作列
- asp.net – 微软的AJAX Toolkit与jQuery
- asp.net-mvc – mvc.net如何在迭代列表时使用强类型助手
- asp.net-mvc – RequireHttps导致Amazon Elastic Load Bala
- asp.net-mvc – 持久化jqGrid列首选项
- ASP.NET MVC – 如何抛出与StackOverflow类似的404页面
- asp.net-mvc – 在哪里可以找到mvc 2的windsor控制器工厂?