开发者

Form Tags in View Not Outputted

开发者 https://www.devze.com 2023-03-02 21:33 出处:网络
The form tags aren\'t displaying. 开发者_如何学JAVA(Really ripping my hair out over this.) I have a view (Index.cshtml):

The form tags aren't displaying. 开发者_如何学JAVA(Really ripping my hair out over this.) I have a view (Index.cshtml):

@section mainmid
{    
  @using (Html.BeginForm("index", "PetSittingRequest"))
  {    
    <h1>    
      @Html.TextBox("awesome")
    </h1>      
  }    
}

And in my _Layout.cshtml:

@RenderSection("mainmid", required: false)
@RenderBody()

The HTML that I'm getting is this. It has no form tags. They're not located anywhere in the HTML source.

<h1>    
  <input id="awesome" name="awesome" type="text" value="" />
</h1>      

Any thoughts? Thanks!


Impossible to reproduce. Steps:

  1. Create a new ASP.NET MVC 3 project
  2. In _Layout.cshtml replace @RenderBody() with:

    @RenderSection("mainmid", required: false)
    @RenderBody()
    
  3. In Index.cshtml put the following:

    @section mainmid
    {    
        @using (Html.BeginForm("index", "PetSittingRequest"))
        {    
            <h1>    
                @Html.TextBox("awesome")
            </h1>      
        }    
    }
    
  4. Run the application
  5. Browse the source and you will find the correct HTML rendered:

    <form action="/PetSittingRequest" method="post">    
        <h1>    
            <input id="awesome" name="awesome" type="text" value="" />
        </h1>      
    </form>
    

Conclusion: your problem lies somewhere else. So next time you ask a question please provide a full example allowing to reproduce the problem (as I did in my answer).

0

精彩评论

暂无评论...
验证码 换一张
取 消