MVC C#登录母版页
|
嘿,
我是mvc .net的新手。
我有一个已登录的母版页。现在,我希望能够从任何页面登录。
但是我似乎无法正常工作。我有一个带有方法登录和母版页的AccountController。
这是母版页上的登录名
<% using (Html.BeginForm(\"LogOn\", \"Account\"))
{ %>
<%: Html.ValidationSummary(true, \"Login foutief. probeer opnieuw.\") %>
<div id=\"login_panel\">
<fieldset>
<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 (persoonRepos.aanmelden(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction(\"Index\", \"Home\");
}
}
else
{
ModelState.AddModelError(\"\", \"The user name or password provided is incorrect.\");
}
}
return View(model);
}
当我测试它时,它不会进入accountmodel LogOn方法。
有人可以帮助我吗?
没有找到相关结果
已邀请:
1 个回复
才改隘瘁
如果您将上述表单直接嵌入到您的MasterPage中,那么它需要注意LogOnModel,因此要使该行的顶部看起来像这样...
当然,请用您的项目名称替换\“ YourProjectName \” ...然后,除非在您的设置中没有看到其他内容,否则在提交登录名时应点击LogOn函数。