The HTML. beginform method does not generate the form tag.

Source: Internet
Author: User

When creating an mvc3 project, I found that some page form labels were not generated (using the @ HTML method), so I had to hand-Write the native form label. Today I decided to find the problem.

My page is like this. A Layout page contains several rendersections and a renderbody.

<body>    @RenderPage("~/Views/Shared/_top.cshtml")    @if (IsSectionDefined("topnav"))    {         @RenderSection("topnav");    }    <!--main start-->    @RenderBody()    <!--main end-->    @if (IsSectionDefined("friendlink"))    {         @RenderSection("friendlink", false);    }    @RenderPage("~/Views/Shared/_Footer.cshtml")    @if (IsSectionDefined("footjs"))    {        @RenderSection("footjs", required: false);    }</body>

Then, on the page, I start to write @ using (html. beginform ()){}

I couldn't write it out, so I started to minimize the test, deleted all the code, and wrote beginform.

Then I started to add code A LITTLE BIT and finally found the problem. My inner page is like this:

@ Section topnav {@ renderpage ("~ /Views/shared/_ headtab. cshtml ", new {current =" guahao "}) @ renderpage ("~ /Views/shared/_ nav. cshtml ", new {step =" member center "})} <Div class =" u_leftbar ">@renderpage ("~ /Views/shared/wedget/_ guide. cshtml ") @ renderpage ("~ /Views/shared/wedget/_ reservetype. cshtml ") </div> <Div id =" Main "> @ using (HTML. beginform ()){//....} <div>

It can be seen that I render four pages, and the problem is above this. What are the differences between the four partialviews?

The difference is that the partialview in the section is rendered by the rendersection method outside the renderbody, while the part written in the DIV label is rendered by the renderbody, when I write the two renderpages into the section, the form tag appears.

This certainly does not solve the problem. The section contains a placeholder and does not guarantee the association with the content layout in the body. Of course, you cannot simply drop the renderpage into the section, in this case, this modular layout also promotes the significance. Originally, it was easy to load various pendants by loading some views, and it is obviously not suitable to write HTML code, so I used the method of loading some views to solve the problem:

<div class="u_leftbar">    @Html.Partial("~/Views/Shared/Wedget/_Guide.cshtml")    @Html.Partial("~/Views/Shared/Wedget/_ReserveType.cshtml")</div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.