MVC3 Razor using Html.BeginForm problem

前端 未结 3 1901
醉梦人生
醉梦人生 2021-01-07 16:46

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

@using (Html.BeginForm()) {

...

相关标签:
3条回答
  • 2021-01-07 17:06

    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(...) { ... } }

    0 讨论(0)
  • 2021-01-07 17:13

    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>
    
    0 讨论(0)
  • 2021-01-07 17:24

    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>
    
    0 讨论(0)
提交回复
热议问题