Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does normal markup inside an @Using Html.BeginForm need an @?

related: MVC3 Razor using Html.BeginForm problem

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

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?

like image 694
just.another.programmer Avatar asked Dec 28 '22 02:12

just.another.programmer


1 Answers

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.

like image 168
Matthew Abbott Avatar answered Jan 17 '23 15:01

Matthew Abbott