无法使用两个提交按钮命中控制器

时间:2017-06-27 19:21:55

标签: asp.net-mvc

我使用了模式弹出窗口,其中包含三个带有关注div的选项卡。在div 1和div 2中,我使用了Login和Register。不幸的是,登录按钮重定向到控制器,而寄存器则没有。 当我交换他们的位置时,注册按钮是重定向的,这次登录提交不起作用。

我的代码如下:

@using(Html.BeginForm("RegisterUser","Home"))
{

 <div class="modal fade bs-modal-sm" id="myModal" tabindex="-1" role="dialog" 
style="font-family:cursive" aria-labelledby="mySmallModalLabel" 
aria-hidden="true">
  <div class="modal-dialog modal-sm">
<div class="modal-content">
    <br>
    <div class="bs-example bs-example-tabs">
        <ul id="myTab" class="nav nav-tabs">
          <li class="active"><a href="#signin" 
              data-toggle="tab">Sign In</a></li>
          <li class=""><a href="#signup" 
              data-toggle="tab">Register</a></li>
          <li class=""><a href="#why" 
              data-toggle="tab">Why?</a></li>
        </ul>
    </div>
    <div class="modal-body">
    <div id="myTabContent" class="tab-content">        
    <div class="tab-pane fade" id="signup">
        <form class="form-horizontal">
        <fieldset>
        <!-- Sign Up Form -->
        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="Email">Email:</label>
          <div class="controls">               
              @Html.TextBoxFor(x => x.Email, new { @class = "form-control input-large",@placeholder = "Joek@irawath.com", @required="" }) 
          </div>
        </div>

        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="userid">Alias:</label>
          <div class="controls">
               @Html.TextBoxFor(x => x.UserName, new { @class = "form-control input-large",@placeholder = "Joek@irawath.com", @required="" })                 
          </div>
        </div>

        <!-- Password input-->
        <div class="control-group">
          <label class="control-label" for="password">Password:</label>
          <div class="controls">
               @Html.TextBoxFor(x => x.Password, new { @class = "form-control input-large",@placeholder = "********", @required="",@type="password" }) 

            <em>1-8 Characters</em>
          </div>
        </div>

        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="reenterpassword">Re-Enter Password:</label>
          <div class="controls">
            <input id="reenterpassword" class="form-control" name="reenterpassword" type="password" placeholder="********" class="input-large" required="">
          </div>
        </div>



        <!-- Button -->
        <div class="control-group">
          <label class="control-label" for="confirmsignup"></label>
          <div class="controls">
           <button id="btnconfirmsignup" type="submit" name="signin" class="btn btn-success" >Sign Up</button>
              @* <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>*@

          </div>
        </div>
        </fieldset>
        </form>
  </div>
    <div class="tab-pane fade active in" id="signin">
        <form class="form-horizontal">
        <fieldset>
        <!-- Sign In Form -->
        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="userid">Alias:</label>
          <div class="controls">
            <input required="" id="userid" name="userid" type="text" class="form-control" placeholder="JoeSixpack" class="input-medium" required="">
          </div>
        </div>

        <!-- Password input-->
        <div class="control-group">
          <label class="control-label" for="passwordinput">Password:</label>
          <div class="controls">
            <input required="" id="passwordinput" name="passwordinput" class="form-control" type="password" placeholder="********" class="input-medium">
          </div>
        </div>

        <!-- Multiple Checkboxes (inline) -->
        <div class="control-group">
          <label class="control-label" for="rememberme"></label>
          <div class="controls">
            <label class="checkbox inline" for="rememberme-0">
              <input type="checkbox" name="rememberme" id="rememberme-0" value="Remember me" style="margin-left:0px">
              Remember me
            </label>
          </div>
        </div>
             <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>
        <!-- Button -->
        <div class="control-group">
          <label class="control-label" for="signin"></label>
          <div class="controls">
           @* <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>*@
          </div>
        </div>
        </fieldset>
        </form>
    </div>  
    <div class="tab-pane fade in" id="why">
    <p>We need this information so that you can receive access to the site and its content. Rest assured your information will not be sold, traded, or given to anyone.</p>
    <p></p><br> Please contact <p> JoeSixPack@Sixpacksrus.com for any other inquiries.</p>
    </div>      
    </div>
  </div>
  <div class="modal-footer">
  <center>
    <button type="button" class="btn btn-default" data-   dismiss="modal">Close</button>
    </center>
  </div>
  </div>
 </div>
 </div>
}

1 个答案:

答案 0 :(得分:0)

您不能在其他表单中使用表单。

您需要重新排列html,以便<form>内的html.beginform标记不再存在。

剃刀视图中的html.beginform会创建一个<form>标记,用于调用Home控制器中的RegisterUser方法。

此外,您的表单标记没有src操作,因此它们实际上不会发布在任何地方...

我会移除第一个html.beginform,并将form代码替换为html.beginform,以便您最终获得

 <div class="modal fade bs-modal-sm" id="myModal" tabindex="-1" role="dialog" 
style="font-family:cursive" aria-labelledby="mySmallModalLabel" 
aria-hidden="true">
  <div class="modal-dialog modal-sm">
<div class="modal-content">
    <br>
    <div class="bs-example bs-example-tabs">
        <ul id="myTab" class="nav nav-tabs">
          <li class="active"><a href="#signin" 
              data-toggle="tab">Sign In</a></li>
          <li class=""><a href="#signup" 
              data-toggle="tab">Register</a></li>
          <li class=""><a href="#why" 
              data-toggle="tab">Why?</a></li>
        </ul>
    </div>
    <div class="modal-body">
    <div id="myTabContent" class="tab-content">        
    <div class="tab-pane fade" id="signup">
         @using(Html.BeginForm("RegisterUser","Home"))
{
        <fieldset>
        <!-- Sign Up Form -->
        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="Email">Email:</label>
          <div class="controls">               
              @Html.TextBoxFor(x => x.Email, new { @class = "form-control input-large",@placeholder = "Joek@irawath.com", @required="" }) 
          </div>
        </div>

        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="userid">Alias:</label>
          <div class="controls">
               @Html.TextBoxFor(x => x.UserName, new { @class = "form-control input-large",@placeholder = "Joek@irawath.com", @required="" })                 
          </div>
        </div>

        <!-- Password input-->
        <div class="control-group">
          <label class="control-label" for="password">Password:</label>
          <div class="controls">
               @Html.TextBoxFor(x => x.Password, new { @class = "form-control input-large",@placeholder = "********", @required="",@type="password" }) 

            <em>1-8 Characters</em>
          </div>
        </div>

        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="reenterpassword">Re-Enter Password:</label>
          <div class="controls">
            <input id="reenterpassword" class="form-control" name="reenterpassword" type="password" placeholder="********" class="input-large" required="">
          </div>
        </div>



        <!-- Button -->
        <div class="control-group">
          <label class="control-label" for="confirmsignup"></label>
          <div class="controls">
           <button id="btnconfirmsignup" type="submit" name="signin" class="btn btn-success" >Sign Up</button>
              @* <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>*@

          </div>
        </div>
        </fieldset>
        } 
  </div>
    <div class="tab-pane fade active in" id="signin">
            @using(Html.BeginForm("RegisterUser","Home"))
{
        <fieldset>
        <!-- Sign In Form -->
        <!-- Text input-->
        <div class="control-group">
          <label class="control-label" for="userid">Alias:</label>
          <div class="controls">
            <input required="" id="userid" name="userid" type="text" class="form-control" placeholder="JoeSixpack" class="input-medium" required="">
          </div>
        </div>

        <!-- Password input-->
        <div class="control-group">
          <label class="control-label" for="passwordinput">Password:</label>
          <div class="controls">
            <input required="" id="passwordinput" name="passwordinput" class="form-control" type="password" placeholder="********" class="input-medium">
          </div>
        </div>

        <!-- Multiple Checkboxes (inline) -->
        <div class="control-group">
          <label class="control-label" for="rememberme"></label>
          <div class="controls">
            <label class="checkbox inline" for="rememberme-0">
              <input type="checkbox" name="rememberme" id="rememberme-0" value="Remember me" style="margin-left:0px">
              Remember me
            </label>
          </div>
        </div>
             <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>
        <!-- Button -->
        <div class="control-group">
          <label class="control-label" for="signin"></label>
          <div class="controls">
           @* <button id="btnsignin" type="submit" name="signin" class="btn btn-success">Sign In</button>*@
          </div>
        </div>
        </fieldset>
        } 
    </div>  
    <div class="tab-pane fade in" id="why">
    <p>We need this information so that you can receive access to the site and its content. Rest assured your information will not be sold, traded, or given to anyone.</p>
    <p></p><br> Please contact <p> JoeSixPack@Sixpacksrus.com for any other inquiries.</p>
    </div>      
    </div>
  </div>
  <div class="modal-footer">
  <center>
    <button type="button" class="btn btn-default" data-   dismiss="modal">Close</button>
    </center>
  </div>
  </div>
 </div>
 </div>

显然,将操作更改为指向控制器中的正确方法 对不起,我在手机上很难输入