我一直在我的應用程序的登錄畫面中使用mvc3和jquery開發時遇到問題,因爲我正在編寫用於在控制器中檢查登錄憑據的代碼以及該控制器事件通過使用jquery開發的buttoon點擊來觸發。當登錄憑證正確時,我想瀏覽其他頁面('/ Customer/CollaborationPortal'),否則我想顯示消息框,指出「憑據錯誤」,這是我的代碼。RedirectToAction不工作,而mvc3表單與jquery的身份驗證
jQuery代碼
$("#btnGo").click(function (e) {
var RegData = getRegData();
if (RegData === null) {
console.log("Specify Data!");
return;
}
$.ajax(
{
url: '/Registration/IsLoginExsit',
type: 'POST',
dataType: 'json',
data: JSON.stringify(RegData),
contentType: 'application/json; charset=utf-8',
success: function (response) {
//window.location.href('/Customer/CollaborationPortal');
Console.Log("success");
error: function() {
//aler('Login error');
Console.Log("error");
}
}
});
});
function getRegData() {
var UserName = $("#txtUserName").val();
var Password = $("#txtPassword").val();
return { "UserName": UserName, "Password": Password };
}
});
控制器代碼
public ActionResult IsLoginExsit(BAMasterCustomerDO loginData)
{
if (!string.IsNullOrEmpty(loginData.UserName) && !string.IsNullOrEmpty (loginData.Password))
{
bool result = Businesss.Factory.BusinessFactory.GetRegistration().IsLoginExist(loginData.UserName, loginData.Password);
if (result)
{
System.Web.HttpContext.Current.Session["UserName"]=loginData.UserName;
return RedirectToAction("/Customer/CollaborationPortal");
}
else
{
ViewData["message"] = "Registration failed";
return View();
}
}
return View();
}
並且還沒有進入 「成功」 和 「錯誤」 的代碼。
在此先感謝。