Alex Rivera | Logout

MVC3 Razor using Html.BeginForm problem

Asked 2011-02-14T09:46:48.163
31

This is probably a simple thing, but ive got the following code:

<div>
    @using (Html.BeginForm()) {
        <p>
            ...
        </p>
    }
</div>

And it keeps complaining that the starting { bracket must be followed by a end } bracket, but its there, and all code examples doing this sort of stuff show this as the way to do it, so im a bit baffled as to why it doesn't work...

Edit
Report

1 Answer

3

It worked for me this way:

  @{ using (Html.BeginForm(...))
     {
      <p>
      Content here
      </p>
     }
  }

The problem is that using is a statement, not an expression, so @csharpexpression won't work. For statements, the razor syntax is to use @{csharpstatement}. But the using statement includes its own pair of curly braces, so it gets a little twisted like @{ using(...) { ... } }

answered 2011-12-02T17:32:43.393

Your Answer