デフォルトのMVC 3アプリケーションをセットアップしましたが、これは初めてですが、入力フィールドから値を印刷しようとしているときに問題があります。送信ボタンをクリックしました。サブミットMVC 3で入力値を取得
これは、下部に送信ボタンがある単純な登録フォームです。送信ボタンをクリックすると、入力フィールドの1つからのテキストが、送信ボタンの下にあるラベルまたは何かに印刷されることが予想されます。私はこれを行う方法を完全に失っています、私はIDを持つラベルを作成しようとしましたが、私は入力フィールドの値またはラベルにアクセスすることができません。
コントローラのアクションは、次のようになります。完全な形は次のようになります
[HttpPost]
public ActionResult Create(Person person)
{
if (ModelState.IsValid)
{
db.Persons.Add(person);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(person);
}
:投稿フォームからのすべての値を取得するために
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<div class="editor-label">
@Html.LabelFor(model => model.Firstname)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Firstname)
@Html.ValidationMessageFor(model => model.Firstname)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Lastname)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Lastname)
@Html.ValidationMessageFor(model => model.Lastname)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Phone)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Phone)
@Html.ValidationMessageFor(model => model.Phone)
</div>
<p>
<button id="btn_Register">
<span class="ui-button-text">Register</span>
</button>
</p>
</fieldset>
}
あなたの 'Controller''アクションの外観はどうですか? –
残りのフォームの外観はどうなっていますか? –
MVCはasp.netとはまったく異なります。 「入力フィールドの値またはラベルにアクセスできない」と言うと、コード内でこれを行うことができると思われますか? –