0

我是 ASP.NET MVC 4 的新手,我正在尝试在 jquery mobile 上创建一个简单的登录表单。我想用 Razor 创建一个简单的 jquerymobile MVC 4 页面,当用户单击提交时,该页面将“发布”。

但是每次我单击“登录”按钮(即提交按钮)时,它都会继续执行我控制器中的“获取”操作。

并且萤火虫也将请求显示为“GET”,请帮助给我一些关于我做错了什么的指导。:(

以下是我的代码,提前谢谢你。

我的观点

@model com.mywebsite.Models.LoginModel

<div data-role="page" data-theme="a" id="main">
            <div data-role="header" id="topbar" data-theme="b">
                <a href="index.html" class="back" data-direction="reverse"></a>
                <div class="header_title">Login</div>
            </div>

  <div data-role="content" data-theme="e"  id="content">
@using (Html.BeginForm("Login", "User", FormMethod.Post, new Dictionary<string,Object> { {"enctype","multipart/form-data"}, {"data-ajax","false"}}))
{
    @Html.ValidationSummary(true, "Login failed. Check your login details.");    

    <fieldset>    
    <div class="container1 " >
    <div class="fblogin"></div>
    <div class="or">Or</div>
  <div class="container1_1">
  <legend>Login</legend>
        <div  class="textwrapper grid">
            <div class="leftcolumn"><label for="name">Email:</label></div>
            <div class="leftcolumn">                
                @Html.TextBoxFor(u => u.UserName, new Dictionary<string,Object> { {"data-theme","d"}, {"id","e"}, {"type","email"}, {"size","20"}})

            </div>
        </div>
     </div>   
        <div  class="textwrapper container1_1">
            <div class="leftcolumn"><label for="password">Password:</label></div>
            <div class="leftcolumn">
                @Html.PasswordFor(u => u.Password, new Dictionary<string,Object> { {"data-theme","d"}, {"id","p"}, {"type","password"}})
            </div>
        </div>    
    </div>   
    <input type="submit" value="Log In" rel="external" data-ajax="false" />

  <div class="fpwd"><a href="index.html" data-theme="d">Forgot Password?</a></div>
  <div class="container1">
          <div class="container1_1">
        <legend>Don't have an account yet?</legend>
        <ul data-role="listview" data-inset="true" data-theme="d" class="nopadding">
        <li ><a href="signup.html"><div class="icon_signup_list"></div>Register</a></li>
        </ul>
        </div>
  </div>
        </fieldset>
}  
<!-- end content-->
</div>

@Html.Partial("~/Views/Shared/_Footer.cshtml")
<!--end page-->
</div>

我的模型(与默认的 MVC 应用程序模板相同)

public class LoginModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Display(Name = "Remember me?")]
    public bool RememberMe { get; set; }
}

我的控制器

public class UserController : Controller
{        
    // GET: /User/
    public ActionResult Login(string returnUrl)
    {
        return View();
    }

    // POST: /User/Login/
   [HttpPost]
    public ActionResult Login(LoginModel user)
    {
        var obj = UserModels.GetUser(user.UserName, user.Password);
        return View();
    }
 }

我的 Global.asax.cs

    public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();


    }

    protected void Application_BeginRequest()
    {
        const string culture = "id";
        CultureInfo ci = CultureInfo.GetCultureInfo(culture);

        Thread.CurrentThread.CurrentCulture = ci;
        Thread.CurrentThread.CurrentUICulture = ci;
    }
}
4

2 回答 2

2

您有嵌套的表单标签:

@using (Html.BeginForm("Login", "User", FormMethod.Post, new Dictionary<string,Object> { {"enctype","multipart/form-data"}, {"data-ajax","false"}}))

<form action="/User/Login" method="post" data-ajax="false">

这两行代码都会产生一个标签。嵌套标签在 HTML 4+ 中是非法的。请删除其中一个表单标签,这应该可以解决问题。

于 2013-02-04T07:11:19.103 回答
0

几天来发现我痛苦的愚蠢错误。

删除了我的 _Layout上的标签,它起作用了。

谢谢@onemancat 的回复,它提示我看看其他领域。

于 2013-02-05T02:50:34.933 回答