Doing a simple test to verify the view name for a controllers action:
var c开发者_运维百科ontroller = new UserController();
var result = controller.Login() as ViewResult;
Assert.AreEqual("Login", result.ViewName);
The result.ViewName is coming back with "", why would this be?
Are you specifying the view name in the controller Login method or are you leaving it at the default value (which is "")?
If you leaving it at the default value, which is common, you need to test for String.Empty instead of "Login".
if you have a view like this
public ActionResult Index()
{
return View();
}
then the ViewName property will take it's default value that is "" and if you specify the view name like this it'll work fine
public ActionResult Index()
{
return View("Index");
}
精彩评论