本文整理汇总了C#中System.Web.Mvc.ViewResult.WithViewData方法的典型用法代码示例。如果您正苦于以下问题:C# ViewResult.WithViewData方法的具体用法?C# ViewResult.WithViewData怎么用?C# ViewResult.WithViewData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.ViewResult
的用法示例。
在下文中一共展示了ViewResult.WithViewData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithViewData_should_throw_if_view_data_type_does_not_match
public void WithViewData_should_throw_if_view_data_type_does_not_match()
{
const string wrongViewDataType = "WrongType";
var result = new ViewResult { ViewData = new ViewDataDictionary(wrongViewDataType)};
result.WithViewData<CustomReferenceTypeViewData>();
}
示例2: WithViewData_should_throw_exception_if_view_data_is_null_and_expected_type_is_value_type
public void WithViewData_should_throw_exception_if_view_data_is_null_and_expected_type_is_value_type()
{
var renderResult = new ViewResult {ViewData = new ViewDataDictionary<CustomReferenceTypeViewData>() };
renderResult.WithViewData<CustomValueTypeViewData>();
}
示例3: WithViewData_should_return_view_data_if_view_data_type_is_implementation_of_generic_interface
public void WithViewData_should_return_view_data_if_view_data_type_is_implementation_of_generic_interface()
{
var expectedData = new List<string> { "a", "b", "c" };
var renderResult = new ViewResult { ViewData = new ViewDataDictionary(expectedData) };
var result = renderResult.WithViewData<IList<string>>();
Assert.That(result, Is.EqualTo(expectedData));
}
示例4: WithViewData_should_return_view_data_if_view_data_type_matches
public void WithViewData_should_return_view_data_if_view_data_type_matches()
{
var expectedData = new CustomReferenceTypeViewData {ID = 2, Name = "Foo"};
var renderResult = new ViewResult {ViewData = new ViewDataDictionary(expectedData)};
var result = renderResult.WithViewData<CustomReferenceTypeViewData>();
Assert.That(result, Is.EqualTo(expectedData));
}
示例5: WithViewData_should_return_null_if_view_data_is_null_and_expected_type_is_reference_type
public void WithViewData_should_return_null_if_view_data_is_null_and_expected_type_is_reference_type()
{
var renderResult = new ViewResult {ViewData = new ViewDataDictionary<CustomReferenceTypeViewData>() };
var result = renderResult.WithViewData<CustomReferenceTypeViewData>();
Assert.That(result, Is.Null);
}