在我的其中一個程序中,我設置了一個「編輯」視圖/操作方法,它可以讓我編輯特定表項的信息。編輯器選項有效,但不會使用當前信息填充編輯器。這導致「編輯」選項看起來與我的「創建」選項相同,這是爲了讓用戶創建一個新條目。爲什麼我的編輯器沒有預先填充?
有什麼我失蹤了嗎?該視圖的代碼似乎與我正在關注的教程幾乎完全相同,但它們顯示的結果是您對「編輯」選項的期望;一位編輯預先填寫了條目的當前信息。
以下是我的視圖和操作方法的代碼。提前致謝。
查看:
@model PharmTrack.Models.Doctor
@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Doctor</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.firstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.firstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.firstName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.lastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.lastName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.lastName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.address, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.address, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.address, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NPI, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NPI, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NPI, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.DEA, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DEA, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DEA, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to Index", "Index")
</div>
操作方法:
public ActionResult Edit(int id)
{
return View();
}
這個問題是最有可能在控制器中。請向我們展示Controller的操作。 – NineBerry
@NineBerry我已經添加了它。我認爲它是微不足道的,因爲它只是返回視圖。當然,如果方法中缺少某些東西,那是有道理的。 – AustinC