ビューでどのように機能するかを理解するのに苦労@Razor
しています。以下のコードは、ユーザーが新しい投稿を作成できるビューです (フォーラムを作成しています)。
私がやりたいことは、<Fieldset>
マークしたコードを変更できないことです。
@model Forum3.Models.Posts
<h2>CreatePost</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
//--- CAN'T EDITED ----
<fieldset>
<legend>Post</legend>
@*SET TopicID*@
@{
Html.HiddenFor(model => model.TopicId);
@Html.Hidden("TopicId",ViewData["currentTopicId"]);
}
//----END----
<div class="editor-label">
@Html.LabelFor(model => model.Text)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Text)
@Html.ValidationMessageFor(model => model.Text)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
<Fieldset
> と>を削除すると、コード
で次<Legend
のエラーが発生します。HiddenFor
Parser Error Message: Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code.
次に、を削除すると、次の@{...}
ようになります。
@Html.HiddenFor(model => model.TopicId);
@Html.Hidden("TopicId",ViewData["currentTopicId"]);
Create
TopicId が自分に設定されていないため、クリックするとエラーが発生しますcurrentTopicId
(これは、 をそのままに<fieldset>
しておくと発生します)
ここで何が起こっているのかわかりません。何か案は?