MVC3两个字段集两个按钮

时间:2013-03-08 10:24:20

标签: asp.net-mvc html5 post

我在MVC3项目中使用bootstrap。我已经实现了Bootstrap选项卡导航功能。

我的麻烦是我需要在每个选项卡上使用自己的字段和提交按钮的不同表单,但是当我单击第二个提交按钮(在第二个选项卡上)时,表单将提交第一个中包含的信息。

我的代码......

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

@*<fieldset>*@

<div class="tabbable"> <!-- Only required for left/right tabs -->
  <ul class="nav nav-tabs">
    <li class="active">
        <a href="#tab1" data-toggle="tab">Usuario</a>
    </li>
    <li>
        <a href="#tab2" data-toggle="tab">Agente</a>
    </li>
  </ul>
  <div class="tab-content">

    <div class="tab-pane active" id="tab1">

    <fieldset>

    <table class="table" border="0" cellspacing="5" >
    <tr> 

    <td>

        @*<td style="border-top:0px;">*@
        <span class="label">Datos del usuario</span>

        <br />
        <br />

        <div class="editor-field" title="User name"> 

            <select>

             <option>usuario numero 1</option>
             <option>usuario numero 2</option>
             <option>usuario numero 3</option>
             <option>usuario numero 4</option>
             <option>usuario numero 5</option>

            </select>

            @*@Html.TextBoxFor(model => model.Users.Name, new { @maxlength = "9", @autocomplete = "off", style = "width: 140px;" })
            @Html.ValidationMessageFor(model => model.Users.Name)*@


       </div> 

       <br />
        <div class="editor-label">
            <span class="label">Login (e-mail)</span> 
        </div>

        <div class="editor-field" title="User Login">
            @Html.TextBoxFor(model => model.Login, new {style = "width: 140px;" })
            @Html.ValidationMessageFor(model => model.Login)

        </div>
        <br />
        <div class="editor-label">
            <span class="label">Password</span> 
        </div>

        <div class="editor-field" title="User Password">

            <span>Se genera automáticamente</span>                       


        </div>

        </td>
        </tr>
    </table>

        <br />
        <br />

     <div style="float: right;">


        <button type="reset" class = "btn btn-warning">
            <i class="icon-fire icon-white"></i> Clear
        </button>

        <button type="submit" class = "btn btn-success">
            <i class="icon-plus icon-white"></i> Create
        </button>

    </div>
    </fieldset>


    </div>



    <div class="tab-pane" id="tab2">

    <fieldset>

    <table class="table" border="0" cellspacing="5" >
    <tr> 
    <td>
        <span class="label">Datos del agente</span>
        <br />
        <br />

        <div class="editor-label">
            <span class="label">Login (e-mail)</span> 
        </div>

        <div class="editor-field" title="Agent Login">

            @Html.TextBoxFor(model => model.Login, new { style = "width: 140px;" })
            @Html.ValidationMessageFor(model => model.Login)


        </div>
        <br />
        <div class="editor-label">
            <span class="label">Password</span> 
        </div>

        <div class="editor-field" title="Agent Password">

            <span>Se genera automáticamente</span> 


        </div>

        <br /><br /><br /><br /><br />

    </td>   
    </tr>
    </table>


        <div style="float: right;">

        <div class = "btn-group">
                <a class="btn" href="#" onclick="location.href='@Url.Action("Index", "Admin", null)';return false;"><i class="icon-ban-circle"></i> Cancel</a>
        </div>

        <button type="reset" class = "btn btn-warning">
            <i class="icon-fire icon-white"></i> Clear
        </button>

        <button type="submit" class = "btn btn-success">
            <i class="icon-plus icon-white"></i> Create
        </button>

        </div>

        </fieldset>

    </div>
  </div>
</div>



}

关于如何使其发挥作用的任何想法?

提前感谢!!

1 个答案:

答案 0 :(得分:1)

您需要在每个标签上显示:

@using(Html.BeginForm())
{
    ...
}

您还需要为至少其中一个指定非默认的后期操作。

拥有一个@Html.ValidationSummary()是可以的,但如果你想在两个实例中看到任何错误,它必须落在标签之外。