The razor asks; when 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> The problem is most likely with your literal Name: Since you are inside a block of code, Razor assumes that the following lines are lines of code. You can avoid this by adding 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 viewer.
The reason your <input> will be fine is because Razor recognizes that it is a markup tag and will write it to the response stream, with Name: it cannot assume that since it is not actual markup tag.
Sometimes the razor gets confused, so you will need to wrap your code inside the html tag. If you do not want to add additional html tags just because the razor does not receive it, you can use the <text> that will be removed.
@using(Html.BeginForm()){ <text> Name: @Html.TextBoxFor(o => o.Name) <input type="submit" value="submit" /> </text> }