我在理解@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
(如果我离开,也会发生这种情况)
我不知道这里发生了什么。有任何想法吗?
谢谢,那就是问题!我没有完全弄清楚如何让模型包含'TopicId',所以我只保留ViewData。 – NoClueBlue 2013-04-25 17:52:43