English 中文(简体)
为什么这部法典回头看不见。
原标题:Why does this code return a view result with no ViewName?

我在一位名叫AdminController的管理人员中有一些守则。

public ActionResult Login()
{
    AdminModel model = new AdminModel();
    return View(model);
}

当我用测试方法检查观点......

 var result = controller.Login();

 //assert
 Assert.IsInstanceOfType(result, typeof(ViewResult));
 Assert.AreEqual("Login", ((ViewResult)result).ViewName);

它没有显示观点名称。 但是,Login认为肯定会返回。 我不禁要问,为什么没有定见名称? 我认为,它违反了行动结果方法的名称?

最佳回答

只有当你在回复意见时确定<代码>viewName参数时,才确定意见。 例如:

return View("Login", model);

Otherwise, if no view name is set it uses the default view.

因此,为了检验缺省观点,你的说法应当写成:

Assert.AreEqual("", ((ViewResult)result).ViewName);
问题回答

暂无回答




相关问题
Using jquery to get a partial view and updating the UI

I need to render a partial view (returned from the controller) to show some customer summary details. This will need to happen when the user clicks on a button. In the the mean time the user can ...

MVC 2 / MVC 3 / MVC 4

MVC 2 我们可以轻松地创造领域。 现在,我的问题涉及nes地区(地区内)。

Asp.Net MVC 2 - Changing the PropertyValueRequired string

Using a resx file in the App_GlobalResources directory, I ve been able to change the default message for the PropertyValueInvalid string of the model validators. But it doesn t work to translate the ...

ASP.NET MVC 3 - What features do you want to see? [closed]

I know a bunch of people that are really enjoying the improvements that ASP.NET MVC 2 made over the first release. I have just started to migrate our MVC 1 project over and so far areas has totally ...

热门标签