Html.BeginForm MVC3内部的Html.BeginForm [英] Html.BeginForm inside of Html.BeginForm MVC3

查看:79
本文介绍了Html.BeginForm MVC3内部的Html.BeginForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个呈现两个局部视图的主视图.主视图包含表单中的两个局部视图.每个局部视图还包含表单.所有3个视图共享相同的视图模型.我想做的是用主视图封装所有视图中的数据,并用局部视图运行特定的Controller动作结果.

I have a main view that renders two partial views. The main view encompasses both of the partial views within a form. Each of the partial views also contain forms. All 3 views share the same viewmodel. What I want to do is encapsulate the data from all views with the main view, and run specific Controller action results with the partial views.

我想知道是否有可能.调试时,我看到我的内容总是发布到主视图"表单的HTTPPost中.我相应地为每个表单都提交了按钮.对不起,这段代码出来了.

I want to know if this is even possible. When debugging I see that my content always posts to the HTTPPost of the Main views form. I have submit buttons for each of the forms accordingly. Sorry for the code post, its coming out all split up.

主视图:

@using (Html.BeginForm("Main", "Registration", FormMethod.Post, 
    new { @class="mainform" }))
{
    <form>
        <fieldset>
            <div id ="option1" class="conglomerate">
                @Html.Partial("_GetBusiness")
            </div> 
            <div id ="option2" class="dealership">
                @Html.Partial("_GetLocation")
            </div>
            <button type="submit" value="Create" class="buttonBlue" id="">
                <span>Create a new dealer</span>
            </button>
         </fieldset>
    </form>

部分1

@using (Html.BeginForm("CreateBusiness", "Business", FormMethod.Post, 
        new { @class="buisinessform" }))
{
    <form>
        <div class="editor-field">
            @Html.DropDownListFor(m =>m.BusinessId, new SelectList(Model.Businesses, 
                "BusinessId", "BusinessName"), "")
        </div>
        <label>Your company not listed? Register yours below:</label>
        <div class="editor-label">
            @Html.LabelFor(model => model.BusinessName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.BusinessName)
            @Html.ValidationMessageFor(model => model.BusinessName)
        </div>
        <button type="Button" value="" class="buttonBlue"id="TestSubmit">
           <span>Add Dealer</span>
        </button>
        <div class ="confirm">
            <button type="submit" value="Create" class="buttonBlue" id="">
                <span>Click here to confirm dealer addition</span>
            </button>
        </div>
    </form>
}

推荐答案

正如Dave所说,嵌套表格不是有效的HTML.它不仅是HTML5,而且是任何版本的HTML.

As Dave mentions, It is not valid HTML to nest forms. It's not just HTML5, but any version of HTML.

在某些情况下,它可能可以在某些浏览器中运行,但是它永远无效.即使它确实起作用,您也永远不能依赖将要发生的事情.最好的做法是在页面上使用多个非嵌套表单.

It might work in some browsers, in certain circumstances, but it is never valid. And you can never depend on what will happen even if it does seem to work. Your best course of action is to use multiple non-nested forms on a page.

您能解释一下为什么您认为需要嵌套表格吗?

Can you explain why you think you need nested forms?

这篇关于Html.BeginForm MVC3内部的Html.BeginForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆