ViewName Returned is Empty
I am performing a unit test and checking if my controller action returns the correct view but for some reason it is always returning empty string.
[When(@"when I go to the search page")]
public void WhenTheUserGoesToTheSearchScreen()
开发者_JAVA技巧 {
_controller = new HomeController();
_result = _controller.Search();
}
[Then(@"the search view should be displayed")]
public void ThenTheSearchViewShouldBeDisplayed()
{
Assert.AreEqual("Search",(_result as ViewResult).ViewName); // ViewName is empty!
}
The ViewName
property will always be empty unless you pass the string name of the view when its returned from your controller action, I.E:
public ActionResult Search()
{
return View("Search");
}
If you just return View()
then ViewName will be an empty string. It's annoying (especially when using MVContrib) but it is what it is.
精彩评论