在 Razor VB.net MVC 中使用无法按预期工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16414271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:30:49  来源:igfitidea点击:

Using in Razor VB.net MVC not work as expected

asp.net-mvcvb.netrazor

提问by tsohtan

I'm not sure why this syntax complain error "Enter is not declared. May be inaccessible due to protection level" and must put "@html(" to get rid the error.

我不确定为什么这个语法会抱怨错误“未声明 Enter。由于保护级别,可能无法访问”并且必须输入“@html(”来消除错误。

This block complain error

这个块抱怨错误

   @Using (Html.BeginForm("GetUser", "UserProfile", FormMethod.Post))
      Enter User id :-  @Html.TextBox("UserId",Model)  -- This line must write in this way @Html("Enter User id :-")
      <input type="submit" value="Submit  data" />  --This line complain ">" expected"
   End Using 

If rewrite the code in this way, the complain gone, but the output display "System.Web.MVC.Html" at the beginning like the image below

用这种方式重写代码,报错消失了,但是输出显示如下图开头的“System.Web.MVC.Html”

       @Html.BeginForm("GetUser", "UserProfile", FormMethod.Post)
       Enter User id :-   @Html.TextBox("UserId",Model) 

    <input type="submit" value="Submit  data" />

enter image description here

在此处输入图片说明

hi nemesv if Use @<Text>
,it's complain this -->"Using must end with End Using." enter image description here

嗨 nemesv 如果使用@<Text>
,它会抱怨这个 -->“使用必须以结束使用结束。” 在此处输入图片说明

采纳答案by nemesv

When you are inside a Usingblock you are in "code mode" in Razor.

当您在一个Using块内时,您在 Razor 中处于“代码模式”。

So you need to use the @:(for single line statements) or @<text> .. </text>(for multi line statements) to switch back to "text mode" and output html.

所以你需要使用@:(对于单行语句)或@<text> .. </text>(对于多行语句)切换回“文本模式”并输出html。

With using @::

随着使用@:

@Using (Html.BeginForm("GetUser", "UserProfile", FormMethod.Post))
      @:Enter User id :-  @Html.TextBox("UserId",Model)  
      @:<input type="submit" value="Submit  data" />
End Using

or with using @<text>:

或使用@<text>

@Using (Html.BeginForm("GetUser", "UserProfile", FormMethod.Post))
      @<text>Enter User id :-</text>  @Html.TextBox("UserId",Model)  
      @<text><input type="submit" value="Submit  data" /></text>
End Using

See also the Combining text, markup, and code in code blockssection for further info.

另请参阅在代码块中组合文本、标记和代码部分以获取更多信息。