c# - asp.net mvc4 razor pass view model to helper -


i want pass view model html helper/ have tried

 public static string generatefulltable(this htmlhelper helper, ienumerable<carsviewmodel> model)         { 

but dont know model be.

does possible make universal helper gets different view models?

yes, it's called generics.

http://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx

edit:

here's 1 example...

public static string generatefulltable<t>(this htmlhelper helper, ienumerable<t> model) {     ... } 

you can further constrain t of specific type or inheriting interface, maybe this:

public static string generatefulltable<t>(this htmlhelper helper, ienumerable<t> model) t : mymodelsinterface {  } 

but depends on needs. hope helps ;)


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -