剃刀要求;使用时做(Html.BeginForm()) [英] razor asks for ; when doing using(Html.BeginForm())

查看:131
本文介绍了剃刀要求;使用时做(Html.BeginForm())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @using(Html.BeginForm()){
名称:
    @ Html.TextBoxFor(O => o.Name)
        <输入类型=提交值=提交/>
    }

这给了错误的 CS1002:;预计

它的工作原理,如果我删除的名称:

如果我这样做,是这样的:

 <形式的行动=@ Url.Action(AddHuman)方法=后>
名称:
    @ Html.TextBoxFor(O => o.Name)
        <输入类型=提交值=提交/>
< /表及GT;


解决方案

问题是最有可能与你的名称:文字。既然你是一个code座内,剃刀假定下一行是code线。 与 @:或通过<$ C $包裹它,你可与prepending 名称逃脱这个C>&LT;文本&GT;&LT; /文字和GT; 。文本标记是特别为剃刀,当它被视图引擎解析将被删除。

原因你的&LT;输入&GT; 将被罚款是剃刀认识到它是一种标记的标签,并将其写入到响应流,使用名称:是不能假设,因为它不是一个实际的标记标签

@using(Html.BeginForm()){
Name:
    @Html.TextBoxFor(o => o.Name)
        <input type="submit" value="submit" />
    }

this gives error CS1002: ; expected

it works if I remove the Name:

or if I do it like this:

<form action="@Url.Action("AddHuman")" method="post">
Name:
    @Html.TextBoxFor(o => o.Name)
        <input type="submit" value="submit" />
</form>

解决方案

The problem is most likely with your Name: literal. Since you are inside a code block, Razor assumes that the next lines are code lines. You can escape this with either prepending Name: with @: or by wrapping it with <text></text>. The text tag is special for Razor and will be removed when it is parsed by the view engine.

The reason your <input> will be fine is that Razor recognizes that it is a markup tag and will write it out to the response stream, with Name: is can't assume that since it isn't an actual markup tag.

这篇关于剃刀要求;使用时做(Html.BeginForm())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆