我正在将现有网站转换为使用MVC和实体框架.
布局/样式应该保持不变,为了遵循该指南,我需要使用< a>提交我的登录表单.标签,因为它有按钮的自定义图像.
这是我的表格:
@using (Html.BeginForm("Login","Login",FormMethod.Post,new { id = "login",action = "Login" })) { <label> <span>Username </span> <input type="text" name="UserName" id="UserName" class="input-text required" /> </label> <label> <span>Password </span> <input type="password" name="Password" id="Password" class="input-text required" /> </label> <label> <input type="checkBox" name="RememberMe" id="RememberMe" class="check-Box" /> <span class="checkBoxlabel">Remember Me</span> </label> <div class="spacer"> <a href="javascript:void(0)" onclick="login();" class="login-button"></a> </div> }
如您所见,< a>标签以前使用javascript提交登录信息.这不是我想要完成的.
如何更改该标签以将我的表单提交给我的控制器操作?
解决方法
我做了一些小改动
HTML
<form action="test.aspx" type="POST"> <label> <span>Username</span> <input type="text" name="UserName" id="UserName" class="input-text required" /> </label> <label> <span>Password</span> <input type="password" name="Password" id="Password" class="input-text required" /> </label> <label> <input type="checkBox" name="RememberMe" id="RememberMe" class="check-Box" /> <span class="checkBoxlabel">Remember Me</span> </label> <div class="spacer"> <a href="javascript:void(0)" class="login-button">Login</a> </div> </form>
jQuery的
$(document).ready(function(){ $(document).on("click",".login-button",function(){ var form = $(this).closest("form"); //console.log(form); form.submit(); }); });