将强类型变量传递给视图的最佳方式是什么?



是否有任何方法可以将多个变量传递给视图,以便我可以使用类型成员和方法?

我想更安全与我的编码?ViewData将不传递强类型

ASP.net 4 MVC 3由于

通常这样做的方法是创建一个具有您需要的各种值的视图模型,即

public class SomeSpecificViewModel {
    public int SomeValue {get;set;}
    public string AnotherValue {get;set;}
    public FancyType MoreComplexValue {get;set;}
}

现在传递一个SomeSpecificViewModel到视图,并告诉你的视图期望一个SomeSpecificViewModel。然后直接访问成员

最新更新