我的 AccountController 上的 Login Action 使用Ε Г И І И О在Redirect to Post Method/Action中提到的技术向我的 StatusController 的 Success Action 发布“登录成功”消息:
/// <returns>
/// If login is successful, returns a view stating such. If the
/// login is not successful, the main Login view will be
/// redisplayed
/// </returns>
[HttpPost]
public ActionResult Login(logIn loginAttempt)
{
logIn theLoginModel = new logIn();
string username = loginAttempt.Username;
string password = loginAttempt.Password;
if (Membership.ValidateUser(username, password)) {
...
/* The login was successful. Redirect to the LoginSucess
* Action success */
status theStatus = new status();
theStatus.Message = Constants.StatusMsgs.LoginSuccess;
StatusController SC = new StatusController();
return SC.Success(theStatus);
} else {
...
return View(theLoginModel);
}
}
我可以使用 VS2010 调试器来验证我的成功操作是否在代码片段中获得了正确的消息:
namespace usedCarLotWebApp.Controllers
{
public class StatusController : Controller
{
/// <summary>
/// Outputs a Success status message to the user
/// </summary>
/// <returns>
/// A trivial view to display a Success status message to the
/// user
/// </returns>
[HttpPost]
public ActionResult Success(status theMessage)
{
return View(viewName: "Success", model: theMessage);
}
}
}
但是当我的状态控制器的成功操作尝试呈现视图时,它会尝试从我的 AccountController 目录而不是我的 StatusController 目录中呈现视图,正如我所期望的那样。
有什么方法可以修改我的 StatusController 的成功操作,以便它总是尝试在我的 StatusController 目录中找到一个成功视图?