我正在将现有网站转换为使用MVC和实体框架.
布局/样式应该保持不变,为了遵循该指南,我需要使用< a>提交我的登录表单.标签,因为它有按钮的自定义图像.@H_301_3@
这是我的表格:@H_301_3@
@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> }
解决方法
我做了一些小改动
HTML@H_301_3@
<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的@H_301_3@
$(document).ready(function(){ $(document).on("click",".login-button",function(){ var form = $(this).closest("form"); //console.log(form); form.submit(); }); });