我有一個非常簡單的登錄頁面。問題出在Login方法中。我執行RedirectToAction,但是,它永遠不會將網頁從登錄頁面更改爲主頁。剃刀重定向包含意外行爲
的HomeController(主要應用控制器)
public ActionResult Index(string username = null, string password = null)
{
if (username == null || password == null)
{
return RedirectToAction("Index", "Auth");
}
this.username = username;
this.password = password;
return View(); //and have tried return View("Index");
}
AuthController(抓住用戶名和密碼)
public ActionResult Login(string username, string password)
{
return RedirectToAction("Index","Home", new { username=username,password=password});
}
按鈕按下
function Login() {
var _get_searchdetails = '@Url.Action("Login", "Auth")';
$.ajax({
url: _get_searchdetails,
data: { username: $('#username').val(), password: $('#password').val() },
type: "POST",
beforeSend: function() {
},
error: function (xhr, textStatus, error) {
alert("Try again!");
},
success: function (htmldata, xhr, settings) {
}
});
}
'類型:「GET」,'* \ * GASP * *在控制器上設置 – adiga
字段是行不通的,因爲所述控制器被實例化,並設置與每個請求。你做的下一個請求,'username'和'password'將再次爲空。 –
是的,我保存那些...... Session [「username」] = login.username; AND Session [「password」] = login.password;謝謝你! – Rob