我在BootstrapBaseController.cs
像MVC4訪問一個控制器的方法將其他
public void Success(string message)
{
TempData.Add(Alerts.SUCCESS, message);
}
我沒有用它又一些內在的方法,但我想它表明我傳遞給該方法的一些成功消息。 我想在我的另一個名爲PortalController
的控制器中使用這種方法。在下面的方法中,我想在用戶添加到數據庫時顯示成功消息。
對此提出建議?
[HttpPost]
public ActionResult Register(RegisterModel user)
{
if (ModelState.IsValid && (user.Password == user.ConfirmPassword))
{
var regUser = _db.Users.Create();
regUser.UserName = user.UserName;
regUser.Password = user.Password;
_db.Users.Add(regUser);
_db.SaveChanges();
}
return View();
}
謝謝,但我只是意識到我沒有被轉發到[HttpPost]行動時,按下注冊按鈕。在點擊註冊按鈕時,它仍然會將我轉到[HttpGet]操作。可能需要作爲新的想法。 – Cybercop
ummm如果我返回像這樣的返回RedirectToAction(「Index」,「Home」)到我的[httpPost] metod,我該如何顯示成功消息。我的註冊視圖使用_BootstrapLayout.empty.cshtml作爲佈局 – Cybercop