我的页面有以下隐藏字段
<%= Html.Hidden("SessionId", Model.Form.UniqueSessionId) %>
我的控制器
public class SomeController
{
public ActionResult Index()
{
var somemode = new GetSomeModel();
return View(somemodel);
}
}
我想能够测试视图是否有隐藏字段
protected SomeController controller;
protected void SetupController()
{
controller = new SomeController()
}
[Test]
public void view_has_hidden_field_for_SessionId()
{
ViewResult result = controller.Index() as ViewResult;
Assert.IsTrue(result.contains("<input type="hidden" id="SessionId" />"));
}
问题是:如何将视图呈现为字符串?有什么帮助吗?