Tag: 局部视图

如何测试PARTIAL视图是在C#ASP .NET MVC中呈现的

我有一个视图,它内部有部分视图渲染: @Html.RenderPartial(“partial”, Model.SomeModelProperty); 还有一个控制器,它返回这个视图 public ActionResult Action() { … var model = new SomeModel(){SomeModelProperty = “SomeValue”} return View(“view”, model); } 如何测试视图呈现我知道: [TestMethod] public void TestView() { … var result = controller.Action(); // Assert result.AssertViewRendered().ForView(“view”).WithViewData(); } 但是当我打电话的时候 result.AssertPartialViewRendered().ForView(“partial”).WithViewData(); 我收到此错误消息 Expected result to be of type PartialViewResult. It is actually of type ViewResult. 我究竟做错了什么?