页面代码:@model MvcMovie.Models.LogOnModel@{
    ViewBag.Title = "Log On";
}<h2>Log On</h2>
<p>
    Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don't have an account.
</p><script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")@using (Html.BeginForm()) {
    <div>
        <fieldset>
            <legend>Account Information</legend>            <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </div>            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>            <div class="editor-label">
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe)
            </div>            <p>
                <input type="submit" value="Log On" />
            </p>
        </fieldset>
    </div>
}后台代码:        [HttpPost]
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    } else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                } else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }            // If we got this far, something failed, redisplay form
            return View(model);
        }
这个action的2个参数是怎么获取到的啊?

解决方案 »

  1.   

    你要理解Controller是做什么的,提供用于响应对 MVC 网站所进行的 HTTP 请求的方法。
    从用户接收请求, 将模型与视图匹配在一起,共同完成用户的请求。Controller的一个重要作用就是负责将获取Model数据,将Model传递给View对象。
    通知View对象,获取数据、显示数据或进行自己的操作。
      

  2.   

    Controller 处理流程:  1. 页面处理流程:
      发送请求->UrlRoutingModule捕获请求–> MvcRouteHandler.GetHttpHandler()–> MvcHandler.ProcessRequest()
      2.MvcHandler.ProcessRequest()处理流程:
      使用工厂方法获取具体的Controller–>Controller.Execute()–>释放Controller对象
      3.Controller.Execute()处理流程:
      获取Action–>调用Action方法获取返回的ActionResult–>调用ActionResult.ExecuteResult()方法
      4.ActionResult.ExecuteResult()处理流程:
      获取IView对象->根据IView对象中的页面路径获取Page类->调用IView.RenderView()方法(内部调用Page.RenderView方法)
      

  3.   

    在java中form表单提交时,我们可以在webconfig中指定这个表单提交到哪个action中
      

  4.   

    相当于request["name"] 如果有跟参数 或者model里的值的name匹配的话会自动把值赋给它
      

  5.   

    http://blog.csdn.net/lutinghuan/article/details/8154523