0

我在 MVC3 项目中使用引导程序。我已经实现了 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>



}

关于如何让它工作的任何想法?

提前致谢!!

4

1 回答 1

1

您需要在每个选项卡上拥有:

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

您还需要为其中至少一个指定非默认发布操作。

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

于 2013-04-18T15:51:09.687 回答