MVC3 部分视图回发不起作用?
我在 AccountController 中有 LogOn 部分视图:
public ActionResult LogOn()
{
return PartialView();
}
//
// POST: /Account/LogOn
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
}
else
{
ModelState.AddModelError("", Resources.Account.Account.LoginFailureText);
}
}
}
return PartialView(model);
}
,我在 _Layout.cshtml 中使用以下方式渲染此部分:
@{Html.RenderAction("LogOn", "Account");}
并且 LogOn.cshtml 视图是:
@model Kalimat.Web.Models.LogOnModel
<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>
<div class="leftbanner login">
<div class="bookicon">
<img src="@Url.Content(@Kalimat.Web.Resources.Common.bookiconImgSrc)" alt="@Kalimat.Web.Resources.Common.bookiconImgAlt" />
</div>
<div class="strip">
@MvcHtmlString.Create(Kalimat.Web.Resources.Account.Account.LoginTitle)
</div>
<div class="shade_2">
<img src="@Url.Content(@Kalimat.Web.Resources.Common.shade_2ImgSrc)" alt="@Kalimat.Web.Resources.Common.shade_2ImgAlt" />
</div>
<div class="insidetext">
@{
//Logined user view
if (Request.IsAuthenticated)
{
<div id="LoginView1">
@{<text>@Kalimat.Web.Resources.Account.Account.WelcomeText <strong>@Model.UserName</strong>!</text>}
<br />
<a id="LoginStatus1" href="">@Kalimat.Web.Resources.Account.Account.LoginStatusText</a>
<a id="ChangePassLinkButton" href="">@Kalimat.Web.Resources.Account.Account.ChangePswText</a>
</div>
}
else
{
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName, new { @class = "inputfield" })
@Html.ValidationMessageFor(m => m.UserName, "*")
<br />
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password, new { @class = "inputfield" })
@Html.ValidationMessageFor(m => m.Password, "*")
<br />
<span class="remove_shop">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</span>
<p>
***<input type="submit" class="submit_Cart" value="@Kalimat.Web.Resources.Account.Account.LoginButtonText" />***
</p>
@Html.ValidationSummary(false, Kalimat.Web.Resources.Account.Account.LoginFailureText)
<a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.NewAccountText</a>
<br />
<a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.RecoverPswText</a>
}
}
</div>
</div>
当我运行应用程序时,LogOn 视图渲染正确,但单击提交按钮时没有任何反应。为什么?
I have LogOn partial view in the AccountController :
public ActionResult LogOn()
{
return PartialView();
}
//
// POST: /Account/LogOn
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
}
else
{
ModelState.AddModelError("", Resources.Account.Account.LoginFailureText);
}
}
}
return PartialView(model);
}
, I render this partial in my _Layout.cshtml with:
@{Html.RenderAction("LogOn", "Account");}
and the LogOn.cshtml view is :
@model Kalimat.Web.Models.LogOnModel
<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>
<div class="leftbanner login">
<div class="bookicon">
<img src="@Url.Content(@Kalimat.Web.Resources.Common.bookiconImgSrc)" alt="@Kalimat.Web.Resources.Common.bookiconImgAlt" />
</div>
<div class="strip">
@MvcHtmlString.Create(Kalimat.Web.Resources.Account.Account.LoginTitle)
</div>
<div class="shade_2">
<img src="@Url.Content(@Kalimat.Web.Resources.Common.shade_2ImgSrc)" alt="@Kalimat.Web.Resources.Common.shade_2ImgAlt" />
</div>
<div class="insidetext">
@{
//Logined user view
if (Request.IsAuthenticated)
{
<div id="LoginView1">
@{<text>@Kalimat.Web.Resources.Account.Account.WelcomeText <strong>@Model.UserName</strong>!</text>}
<br />
<a id="LoginStatus1" href="">@Kalimat.Web.Resources.Account.Account.LoginStatusText</a>
<a id="ChangePassLinkButton" href="">@Kalimat.Web.Resources.Account.Account.ChangePswText</a>
</div>
}
else
{
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName, new { @class = "inputfield" })
@Html.ValidationMessageFor(m => m.UserName, "*")
<br />
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password, new { @class = "inputfield" })
@Html.ValidationMessageFor(m => m.Password, "*")
<br />
<span class="remove_shop">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</span>
<p>
***<input type="submit" class="submit_Cart" value="@Kalimat.Web.Resources.Account.Account.LoginButtonText" />***
</p>
@Html.ValidationSummary(false, Kalimat.Web.Resources.Account.Account.LoginFailureText)
<a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.NewAccountText</a>
<br />
<a class="submit_Cart" href="">@Kalimat.Web.Resources.Account.Account.RecoverPswText</a>
}
}
</div>
</div>
when I run the application the LogOn view render correct but when clicking on the submit button nothing happens. why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先停止复制这一行
没有意义...
因为通过查看您的代码,您已经提交按钮和所有内容,但我认为您缺少的
是 Ajax.BeginForm() 的参数:
这是因为您使用 ajax 来发布你的行动...
first stop duplicating this line
doesn't make sense ...
as by looking to your code, you have submit button and everything but i think you missing
here is the parameters for Ajax.BeginForm():
this is because you using ajax to post your action ...
我看不到您是否以表格形式提交?
您应该在您的登录位周围添加:
来提交信息?
I cannot see if you have your submit in a form?
you should be adding:
around your login bits to submit the information?
请检查您是否在表单中添加了任何将为空的隐藏字段。简而言之,应该没有任何内容不需要为 null 并作为 null 发布。
例如,我正在发布带有 ID(主要)隐藏字段的表单(用于创建),因此在创建实例中 Id 将为空,因此模型有效,并且它看起来像任何未发布的内容。
Please, check if you have added any hidden field in the form that is going null. In simple words, there should be nothing that not required to null and posting as null.
For example, I was posting form (For create) with hidden field of ID (Primary), so Id will be null in the create instance so model is in valid and its looking like any thing not posting.