为什么一个@using Html.BeginForm内正常标记需要一个@? [英] Why does normal markup inside an @Using Html.BeginForm need an @?
问题描述
相关:使用Html.BeginForm问题
related: MVC3 Razor using Html.BeginForm problem
当我做一个HTML表单的MVC 3 / VB剃刀引擎,我会希望能够做到这样的:
When I make an HTML form for MVC 3/VB with the Razor engine, I would expect to be able to do it like this:
@Using Html.BeginForm("Action", "Controller")
<fieldset>
@* Other form code and values *@
</fieldset>
End Using
但如果我这样做,我得到BC32035:。属性说明不是一个完整的语句中使用续行的属性应用到下面的语句我需要开始标记前加一个@字符来避免这个错误。有人能解释为什么吗?
But if I do that I get "BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement." I need to add an @ character before the opening tag to avoid this error. Can someone explain why?
推荐答案
在使用剃须刀使用C#,你描述什么是可能的,因为解析器能够确定明确的,就是因为标记从code的转移'&LT;'在HTML字符不是有效的C#标记。 VB.NET直接支持内联XML在code,所以剃刀解析器不能确定您已转换回标记,所以你必须要更加明确。
When using Razor with C#, what you describe is possible, because parser can determine the transition from code to markup because of the explicit '<' characters in html is not a valid C# token. VB.NET supports inline XML directly in code, so the Razor parser cannot determine that you have transitioned back to markup, so you have to be more explicit.
这篇关于为什么一个@using Html.BeginForm内正常标记需要一个@?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!