ASP.NETMVC:为什么我的视图将空模型传递回我的控制器?我不明白为什么我的视图只将模型的NULL传递给我的控制器。这是一个编辑后的方法。我用EditPost方法检查了其他控制器,这些方法的结构与这个方法相同,它们工作得很好。它似乎只是这个观点和控制器。以下是我的看法:@model Non_P21_Quote_System_v1._0.Models.gl_code@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";}<h2>Edit</h2>@if (TempData["Message"] != null){
<div style="color:green">
@TempData["Message"]
</div><br />}@if (ViewBag.error != null){
<div style="color:red">
<h3>@ViewBag.error</h3>
</div><br />}@using (Html.BeginForm()){
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>gl_code</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ID)
<div class="form-group">
@Html.LabelFor(model => model.GL_code, "GL Code", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.GL_code, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.GL_code, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.GL_description, "Gl Description", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.GL_description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.GL_description, "", new { @class = "text-danger" })
</div>
</div>调试它时,我看到传入的模型值为NULL。我在控制器端看到了这一点,在编辑方法的参数部分。
2 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
gl_code
gl_code
gl_code=someValue
DefaultModelBinder
someValue
someValue
gl_code gl_code = "someValue";
null
.
慕莱坞森
TA贡献1810条经验 获得超4个赞
public async Task<ActionResult> Edit(gl_code gl_code)
public async Task<ActionResult> Edit(gl_code model)
添加回答
举报
0/150
提交
取消