I'm using ASP.NET MVC 5 and Visual Studio Express 2013. I have this small form in a C# project:
<body>
@using (Html.BeginForm())
{
<p>Your name: @Html.TextBoxFor(x => x.Name) </p>
<p>Your email: @Html.TextBoxFor(x => x.Email) </p>
<p>Your phone: @Html.TextBoxFor(x => x.Phone) </p>
}
</body>
I tried to translate the code above into VB.NET as shown below:
<body>
@Using Html.BeginForm()
<p>Your name: @Html.TextBoxFor(Function(m), m.Name)</p>
<p>Your email: @Html.TextBoxFor(Function(m), m.Email)</p>
<p>Your phone: @Html.TextBoxFor(Function(m), m.phone)</p>
End Using
</body>
I have blue lines under the 'Your' in each "P" element. The hint-help when I hover over the blue line is 'Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.'.
When I debug the page, the error is 'BC30201: Expression expected.' on the line where the @Using occurs.
What am I doing wrong?
BeginForm(HtmlHelper) Writes an opening <form> tag to the response. The form uses the POST method, and the request is processed by the action method for the view. BeginForm(HtmlHelper, String, String, Object, FormMethod, Object)
BeginForm() will create a form on the page that submits its values to the server as a synchronous HTTP request, refreshing the entire page in the process. Ajax. BeginForm() creates a form that submits its values using an asynchronous ajax request.
The value will only be added as query string values if its FormMethod. Get (and you can remove the route values from the BeginForm() method). But what is the point of this - they are hidden inputs, not editable values.
As @rogerdeuce surmised, you do not need the second @
symbol.
@
is used to switch context from VB code to HTML/text.
So the correct code would look like:
<body>
@Using Html.BeginForm()
@<p>Your name: @Html.TextBoxFor(Function(m) m.Name)</p>
@<p>Your email: @Html.TextBoxFor(Function(m) m.Email)</p>
@<p>Your phone: @Html.TextBoxFor(Function(m) m.phone)</p>
End Using
</body>
Or you could use the @<text>
shortcut:
<body>
@Using Html.BeginForm()
@<text>
<p>Your name: @Html.TextBoxFor(Function(m) m.Name)</p>
<p>Your email: @Html.TextBoxFor(Function(m) m.Email)</p>
<p>Your phone: @Html.TextBoxFor(Function(m) m.phone)</p>
</text>
End Using
</body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With