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...

1
  • Tried removing the <p> tags and its still dying on me: Parser Error Message: The using block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup. Commented Feb 14, 2011 at 13:05

3 Answers 3

36

Probably there is an error in the code within the <p> and </p> tags.

Try commenting it out and see what the result is:

<div>
    @using (Html.BeginForm()) {
        <p>
                    @*  = Server side comment out.
                    ....
                    *@
        </p>
    }
</div>
Sign up to request clarification or add additional context in comments.

3 Comments

Being an idiot, it seems there was an unclosed quotation mark on a child element (value="Submit), which seemed to have been causing the issues :(
You're not an idiot just for that. That would mean I'm an idiot everyday. Uh-oh...
Yes even something as simple as a missing end div tag </div> could cause this. Just mentioning this since everyone is using bootstrap today and this could easily be the cause if you moved a form end brace up in your html cod.e
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(...) { ... } }

Comments

0

In my case I was missing a closing div which caused a similar error.

Error Code:

<div>
@using (Html.BeginForm()) {
    <div><p>
                @*  = Server side comment out.
                ....
                *@
    </p>
}
</div>

Resolved:

<div>
@using (Html.BeginForm()) {
    <div><p>
                @*  = Server side comment out.
                ....
                *@
    </p></div>
}
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.