Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

razor asks for ; when doing using(Html.BeginForm())

@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>
like image 962
Omu Avatar asked Jan 17 '11 13:01

Omu


People also ask

What is @using HTML BeginForm ()) in MVC?

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.

What does HTML BeginForm do?

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.

What is the difference between Ajax BeginForm and HTML BeginForm?

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.

What is Razor syntax in MVC?

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.


1 Answers

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.

like image 54
Brian Ball Avatar answered Nov 23 '22 14:11

Brian Ball