@using(Html.BeginForm()){
Name:
@Html.TextBoxFor(o => o.Name)
<input type="submit" value="submit" />
}
this gives error CS1002: ; expected
it works if I remove the Name:
or if I do it like this:
<form action="@Url.Action("AddHuman")" method="post">
Name:
@Html.TextBoxFor(o => o.Name)
<input type="submit" value="submit" />
</form>
Html. BeginForm is the Html Helper Extension Method that is used for creating and rendering the form in HTML. This method makes your job easier in creating form. Here, is the method to create a form using Html.
BeginForm(HtmlHelper, String, String, FormMethod, Object)Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method and includes the HTML attributes.
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.
Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.
The problem is most likely with your Name:
literal. Since you are inside a code block, Razor assumes that the next lines are code lines. You can escape this with either prepending Name:
with @:
or by wrapping it with <text></text>
. The text tag is special for Razor and will be removed when it is parsed by the view engine.
The reason your <input>
will be fine is that Razor recognizes that it is a markup tag and will write it out to the response stream, with Name:
it can't assume that since it isn't an actual markup tag.
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