是MicrosoftAjax.js
,MicrosoftMvcAjax.js
和MicrosoftMvcValidation.js
过时的ASP.NET MVC 3的?我无法在网上找到关于此的更多信息,但从我所看到的内容暗示这些文件在ASP.NET MVC 1-2中使用,并被替换为jquery.validate.min.js
,jquery.unobtrusive-ajax.min.js
和jquery.validate.unobtrusive.min.js
.那是对的吗?我还需要Microsoft文件吗?
我想构建一个登录表单,该表单显示在我站点中每个页面的侧栏中.如果用户输入了错误的用户/通行证,我希望错误显示在此表单上方(页面的其余部分保持原样),如果他成功登录,我希望表单更改为列表有关用户的信息(同样,页面的其余部分与登录前相同).我正在使用带有默认Internet应用程序模板的MVC 3 Web应用程序项目.我有这个:
_Layout.cshtml
@{
if (User.Identity.IsAuthenticated)
{
Html.RenderAction("ShowUserInfo", "User");
}
else
{
Html.RenderAction("LogIn", "User");
}
}
Run Code Online (Sandbox Code Playgroud)
UserController的
[ChildActionOnly]
public PartialViewResult ShowUserInfo()
{
// populate loggedInInfo from database based on
// User.Identity.Name
return PartialView("_LoggedInInfo", loggedInInfo);
}
private ActionResult RedirectToPrevious(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("index", "");
}
}
[ChildActionOnly]
public PartialViewResult LogIn()
{
return PartialView("_LogInForm");
}
//
// POST: /User/LogIn
[HttpPost]
public ActionResult LogIn(LogInModel …
Run Code Online (Sandbox Code Playgroud) 在部分视图中提交表单时,如何防止页面重新加载?有很多例子,但似乎没有一个例子对我有用。这就是我所拥有的。局部视图(Razor)调用此:
@using (Ajax.BeginForm("SaveReply", "Home", null, new AjaxOptions { HttpMethod = "Post" }, new { target = "_self" }))
{
<div class="input-group wall-comment-reply" style="width:100%">
@Html.Hidden("eventid", @item.EventID)
<input name="txtReply" type="text" class="form-control" placeholder="Type your message here...">
<span class="input-group-btn">
<button class="btn btn-primary" id="btn-chat" type="submit">
<i class="fa fa-reply"></i> Reply
</button>
</span>
</div>
}
Run Code Online (Sandbox Code Playgroud)
然后在控制器中有我的操作方法:
[HttpPost]
public void SaveReply(string txtReply, string eventid)
{
//some code
}
Run Code Online (Sandbox Code Playgroud)
控制器动作被触发,但是之后它会自动重定向到localhost / home / SaveReply
也许问题在于此局部视图是从字符串渲染的。我从以下代码中获取了代码:
如何在ASP.NET MVC 3中将Razor View呈现为字符串?
除了其他我尝试过的东西:
我将不胜感激任何帮助。