您好,我有以下問題: 我試圖通過表單發佈一個模型到其他控制器的行動。 但收到的模型只填充了「null」元素。 Html.BeginForm發佈模型爲空
ToolController.cs
public class ToolController : Controller
{
private IDevelopmentStepProvider _devProv;
public ToolController(IDevelopmentStepProvider devtool, IToolProvider tool, IDevelopmentStepVersionsProvider versProv)
{
_devProv = devtool;
}
public ActionResult Index()
{
var Model = new EditToolModel();
/*
* assigning some data to Model
*/
return View(Model);
}
[HttpPost]
public ActionResult EditToolOverview(EditToolModel myModel)
{
return RedirectToAction("Index", "Tool", new { show = "overview" });
}
}
EditToolModel.cs
public class EditToolModel
{
public Tools tool;
public IEnumerable<Tools> tools { get; set; }
public ToolsExtention tool_extention;
public string latest_version { get; set; }
public string latest_version_type { get; set; }
public string latest_devStep { get; set; }
public IEnumerable<ToolVersionsView> versions { get; set; }
public IEnumerable<DevelopmentStep> developmentSteps { get; set; }
}
Index.cshtml
@model EditToolModel
@{
ViewBag.Title = "Index";
Layout = "~/Layout/_Layout.cshtml";
}
@Html.Partial("ToolOverview", this.Model)
ToolOverview.cshtml
@model EditToolModel
@using (Html.BeginForm("EditToolOverview", "Tool", FormMethod.Post))
{
<div class="contend">
@Html.TextBoxFor(Model => Model.tool_extention.a)
@Html.TextBoxFor(Model => Model.tool_extention.b)
@Html.TextBoxFor(Model => Model.tool_extention.c)
@Html.TextBoxFor(Model => Model.tool_extention.d)
<input type="submit" id="tool_submit" name="tool_submit" value="Submit" class="btn submit"/>
</div>
}
不是'@ Html.TextBoxFor(Model => Model.tool_extention.a)'但是@@ Html.TextBoxFor(m => m.tool_extention.a)' – demo