我有一个outerViewModel,里面有两个ViewModel,当我尝试绑定innermodel时,所有属性都为null...
这是代码:
**Models.cs**
public class OuterModel
{
public FirstInnerModel firstInnerModel;
public SecondInnerModel secondInnerModel;
}
public class FirstInnerModel
{
public string Title;
}
public class SecondInnerModel
{
public string Title;
}
索引.cshtml
@using (Html.BeginForm("ActivateFirst", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-label">
@Html.LabelFor(model => model.firstInnerModel.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.firstInnerModel.Title)
@Html.ValidationMessageFor(model => model.firstInnerModel.Title)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
家庭控制器.cs
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
var model = new OuterModel()
{
firstInnerModel = new FirstInnerModel(),
secondInnerModel = new SecondInnerModel()
};
return View(model);
}
[HttpPost]
public void ActivateFirst(FirstInnerModel ggg)
{
}
ggg.Title 返回空...
任何人?帮助!