Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using in Razor VB.net MVC not work as expected

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.

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

       @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

like image 672
tsohtan Avatar asked May 07 '13 08:05

tsohtan


1 Answers

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.

like image 176
nemesv Avatar answered Oct 16 '22 11:10

nemesv