RedirectToAction之后没有视图显示
After RedirectToAction no View displays
我有一个登录页面。验证后,我重定向到所需的页面。它重定向但是No
查看appers,而不是显示以前的登录页面视图。
这是我的Javascript代码
function abc() {
var email = document.forms["MyForm"]["Email"].value;
var password = document.forms["MyForm"]["Password"].value;
if (email.length == 0 || password.length == 0) {
alert("Email and Password Field Required");
return false;
}
else {
$.ajax({
url: $("#MyForm").attr('action'),
type: $("#MyForm").attr('method'),
data: $("#MyForm").serialize(),
success: function (data) {
alert("Invalid Email or Password");
}
});
}
}
</script>
,这是控制器(HttpPost)
public ActionResult UserLogin(Models.UserModel selectedDocuments)
{
if (ModelState.IsValid)
{
long AdminID = IsValid(selectedDocuments.Email, selectedDocuments.Password);
if (AdminID != 0)
{
FormsAuthentication.SetAuthCookie(selectedDocuments.Email, false);
if (RoleID == 1)
{
Session["SystemAdmin"] = true;
Session["AdminID"] = AdminID;
return RedirectToAction("ClubInfo", "Admin");
}
if (RoleID == 2)
{
Session["ClubAdmin"] = true;
Session["AdminID"] = AdminID;
return RedirectToAction("ClubInfo", "ClubAdmin");
}
if (RoleID == 3)
{
Session["NewsAdmin"] = true;
Session["AdminID"] = AdminID;
return RedirectToAction("ClubInfo", "NewsAdmin");
}
}
else
{
ModelState.AddModelError("", "Login Data Is Incorrect.");
}
}
return Json(new { selectedDocuments = "Whatever you want to send" }, JsonRequestBehavior.AllowGet);
}
谁来告诉我怎样才能成功。
由于表单是通过ajax调用发布的,视图将作为ajax调用的响应返回,用户将无法查看重定向的视图。
用return Json
代替reutrn RedirectToAction()
,从客户端重定向:
return Json(new
{
RedirectUrl= Url.Action("ClubInfo", "Admin")
}
,JsonRequestBehavior.AllowGet);
和ajax的in success函数:
success: function (data) {
window.location.href = data.RedirectUrl;
}
我通过改变重定向来实现
返回Json (Url。操作("ClubInfo"、"Admin"));
和javascript中的
$.ajax({
url: $("#MyForm").attr('action'),
type: $("#MyForm").attr('method'),
data: $("#MyForm").serialize(),
success: function (result) {
window.location.href = result;
},
error:function ()
{
alert("Invalid Email or password");
}
});
相关文章:
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- FF视图源|脚本高亮显示为红色
- 有没有比在app.js上绑定模块名称更好的方法来动态加载视图模型和视图以显示模态
- 如何在MVC3中显示鼠标悬停在文本上的部分视图
- 如何应用带过滤器的ng if来过滤记录,并在同一页面中显示两个不同的视图
- 为什么我的视图没有显示在角度ui视图中
- 使用PhoneGap和jQuery Mobile在android设备上显示动态列表视图
- 使用Ruby数组使用JS在视图中进行迭代和显示
- 滑动视图 - 显示下一项的预览/片段
- 在剃须刀应用程序中将视图显示为灯箱
- ember.js如何为视图显示不同的筛选列表?复杂的设置
- ng重复视图显示与JSON数据不对应
- RedirectToAction之后没有视图显示
- ASP.. NET MVC控制器/视图显示本地时间
- 离子弹出窗口视图显示在离子模态视图后面
- WinJs列表视图显示:无带ID的tile
- 完整的日历视图显示goToDate分前,下和今天
- 如何从父数组视图显示子对象视图
- CouchApp视图显示将为空结果
- 在树状视图显示中只打开一个li节点