私のプログラムの1つでは、特定のテーブルエントリの情報を編集できる「編集」ビュー/アクションメソッドを設定しました。エディタオプションは機能しますが、エディタに現在の情報が入力されません。この結果、「編集」オプションは、ユーザーが新しい項目を作成できるようにするための「作成」オプションと同じに見えます。エディタが事前に入力されていないのはなぜですか?
紛失しているものがありますか?ビューのコードは、私が従っていたチュートリアルとほとんど同じように見えましたが、結果は "編集"オプションから期待されるものであることが示されました。エントリの現在の情報で事前設定されたエディタ
以下は、私のビューとアクションメソッドのコードです。前もって感謝します。
ビュー:
@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();
}
問題は、コントローラの中で最も可能性が高いです。このためのコントローラのアクションを私たちに示してください。 – NineBerry
@NineBerry私はそれを追加しました。私はそれが無視されたと仮定しました。もちろん、メソッドから何かが欠落している場合、それは意味をなさないでしょう。 – AustinC