MVC局部登录控制 [英] MVC Partial Login Control
问题描述
所有即时试图做的是创造,我要在我的主页上放置一个登录控制。
All im trying to do is create a login control that i want to place within my home page.
香港专业教育学院创建了一个登录用户控制如下:
Ive created a Login User Control as follows:
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of MyWebsite.LogOnModel)" %>
<% Using Html.BeginForm() %>
<%: Html.ValidationSummary(True, "Login was unsuccessful. Please correct the errors and try again.")%>
<div>
<div class="editor-label">
<%: Html.LabelFor(Function(m) m.UserName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(m) m.UserName) %>
<%: Html.ValidationMessageFor(Function(m) m.UserName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(m) m.Password) %>
</div>
<div class="editor-field">
<%: Html.PasswordFor(Function(m) m.Password) %>
<%: Html.ValidationMessageFor(Function(m) m.Password) %>
</div>
<div class="editor-label">
<%: Html.CheckBoxFor(Function(m) m.RememberMe) %>
<%: Html.LabelFor(Function(m) m.RememberMe) %>
</div>
<p>
<input type="submit" value="Log On" />
</p>
</div>
<% End Using %>
我比家里的Index.aspx页面上呈现这样的:
I than rendered this on the home index.aspx page:
Html.RenderPartial("UsrCtlLogin")
这显示正确的主页上。但我的问题是我如何把它挂到了的AccountController逻辑。即在登录点击我希望它火登录HTTP方法和验证用户(如果提供无效571无效信息),并比他们重定向到一个页面,如果他们是成功的。
It shows up correctly on the home page. But my question is how do i hook it up to the AccountController logic. i.e. On click of login i want it to fire the LogOn http method and validate the user (show invalid message if invalid details are supplied) and than redirect them to a page if they are successful.
我如何创建用户控制和的AccountController之间的联系?
How do i create the link between the user control and the AccountController?
在此先感谢
推荐答案
默认情况下,表格将张贴到当前的URI。因此,如果这是你的主页,你可以在你的家控制器创建一个方法:
By default the form will post to the current uri. So if this is your home page, you can create a method in your home controller:
[HttpPost]
public ActionResult Index() {
//authenticate
return View();
}
但是,你真的不想混控制器职责。因此,改变你的行动方式张贴到/用户/登录,或者你想在你的AccountController任何POST方法。
But you don't really want to mix controller responsibilities. So change your forms action to post to /users/login or whatever post method you want in your AccountController.
using (Html.BeginForm("Login", "Account", FormMethod.Post))
这篇关于MVC局部登录控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!