简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM