Using in Razor VB.net MVC not work as expected

后端 未结 1 1241
南方客
南方客 2021-01-12 04:10

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.

Thi

相关标签:
1条回答
  • 2021-01-12 04:16

    When you are inside a Using block you are in "code mode" in 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.

    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>:

    @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 blocks section for further info.

    0 讨论(0)
提交回复
热议问题