【问题标题】:BeginUmbracoForm not rendering actionBeginUmbracoForm 不呈现动作
【发布时间】:2017-04-24 21:25:41
【问题描述】:

我正在尝试使用 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">

【问题讨论】:

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


    【解决方案1】:

    试试这个:

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

    还值得在这里查看BeginUmbracoForm 重载和文档:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      • 2013-08-19
      • 1970-01-01
      • 2020-02-10
      • 1970-01-01
      相关资源
      最近更新 更多