What is the best way to pass strongly typed variables to the view

191 Views Asked by At

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

1

There are 1 best solutions below

2
On BEST ANSWER

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.