【发布时间】:2017-02-24 20:38:58
【问题描述】:
我有一个无法将值绑定到我的模型的表单。模型在发布操作时为空。
我已将所有内容简化为最简单的示例,但仍然无法绑定。
型号
public class simplemodel
{
public string SomeVal;
}
景色
@model MyApp.Models.simplemodel
@using(Html.BeginForm("Index", "Test", FormMethod.Post))
{
@Html.TextBoxFor(m => m.SomeVal);
<input type="submit" value="submit" id="btnSubmit" />
}
控制器动作
[HttpPost]
public ActionResult Index(simplemodel model)
{
string ReceivedVal = model.SomeVal;
//do whatever...
}
这很简单,但我的模型没有绑定。
ReceivedVal 始终为空。我有很多其他地方可以毫无问题地绑定到模型。我很困惑。我可能会错过什么?
如果我将控制器操作更改为接收 FormCollection,我确实会收到“SomeVal”。所以我知道它已正确发布,只是不会绑定到模型。
【问题讨论】:
-
请注意,model-view-controller 标签是针对有关模式的问题。 ASP.NET-MVC 实现有一个特定的标记。
-
愿你能提供你的原始html
标签: asp.net-mvc binding model