Question

Is there any way that I can pass multiple variables to a view so I can work with the type members and methods?

I want to be more safe with my coding? ViewData will not pass strongly typed.

ASP.net 4 MVC 3 Thanks

Était-ce utile?

La solution

Usually the way to do this is to create a view-model that has the various values you need, i.e.

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

Now pass a SomeSpecificViewModel to the view, and tell your view to expect a SomeSpecificViewModel. Then just access the members.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top