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。我在控制器端看到了這一點,在編輯方法的參數部分。
ASP.NETMVC:為什么我的視圖將空模型傳遞回我的控制器?
鳳凰求蠱
2019-06-21 13:27:06