VSが[HttpGet] Create
の強い型指定のビューを作成した場合、モデルのマークアップは次のようになります。私はHtml.HiddenFor(モデル=> model.Id)を削除することができ、アプリはまだ動作します。それはなんのためですか?
簡潔にするために、コードは簡略化されています。重要な点は、VSがではなく、を含むことです。Html.HiddenFor(model=>model.Id)
が含まれています。
//Create.cshtml
@model MvcMovie.Models.Movie
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Movie</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ReleaseDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ReleaseDate)
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
今、私は次のようにテンプレートHTMLヘルパーEDITORがタイプMovie
ためMovie.cshtml
という名前作成します。
簡潔にするために、コードは簡略化されています。重要な点は、VS DOESには、Html.HiddenFor(model=>model.Id)
が含まれています。
//Movie.cshtml
@model MvcMovie.Models.Movie
@Html.HiddenFor(model => model.Id)
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ReleaseDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ReleaseDate)
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
私は、このテンプレートを使用する場合は、次のように、私はCreate.cshtml
を変更する必要があります。
//Create.cshtml
@model MvcMovie.Models.Movie
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Movie</legend>
@Html.EditorForModel()
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
を質問は、次のとおりです。
- 隠しフィールドのフォームがなく削除することができますので、副作用、この場合、隠されたフィールドは何ですか?