BeginUmbracoForm无法渲染动作

时间:2017-04-24 21:25:42

标签: c# asp.net-mvc forms umbraco umbraco7

我尝试使用mvc umbraco创建简单的登录表单,但是它没有像BeginUmbracoForm那样命中控制器而不输出动作名称。无法弄清楚为什么不是。

以下是我的代码

查看

 <h3> Login</h3>

                @using (Html.BeginUmbracoForm("SubmitLogin", "Login", System.Web.Mvc.FormMethod.Post, new { id = "login" }))
                {
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true, "", new { @class = "alert text-danger" })
                    <form>
                        <!-- Text input-->
                        <div class="form-group">

                            @Html.LabelFor(m => m.Email, new { @class = "control-label" })<span class="required">*</span>
                            @Html.TextBoxFor(m => m.Email, new { @class = "form-control input-md0", required = "required", type = "email" })
                            @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
                        </div>
                        <!-- Text input-->
                        <div class="form-group">
                            @Html.LabelFor(m => m.Password, new { @class = "control-label" })<span class="required">*</span>
                            @Html.TextBoxFor(m => m.Password, new { @class = "form-control input-md", required = "required", type = "password" })
                        </div>

                        <!-- Button -->
                        <div class="form-group">
                            @Html.ValidationSummary()
                            <button id="submit" name="submit" type="submit" class="btn btn-primary btn-lg">Login</button>
                            <a href="forget-password.html" class="pull-right"> <small>Forgot Password ?</small></a>
                        </div>
                    </form>




                }

控制器

 public class LoginController : SurfaceController
    {

        // GET: /Login/     
        public ActionResult RenderLogin()
        {
            var model =new  LoginModel();
          return  PartialView("~/Views/Partials/Forms/LoginForm.cshtml", model);
        }


        [HttpPost]
        [ActionName("SubmitLogin")]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitLogin(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    UrlHelper myHelper = new UrlHelper(HttpContext.Request.RequestContext);
                    if (myHelper.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return Redirect("/login/");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The username or password provided is incorrect.");
                }
            }
            return CurrentUmbracoPage();
        }

}

Html输出

<form action="/login" enctype="multipart/form-data" id="login" method="post">

1 个答案:

答案 0 :(得分:0)

请改为尝试:

@using (Html.BeginUmbracoForm<LoginController>("SubmitLogin", new { id = "login" })) {

}

此处还需要查看BeginUmbracoForm重载和文档:

https://our.umbraco.org/Documentation/Reference/Templating/Mvc/Forms