Is there a way to use something like this: System.Web.Mvc.ViewUserControl<DateTime>? I get an exception that the type is a value type, not a reference type. What is the proper way to resolve this? Thanks.
Edit
What I am trying to accomplish is having a control that takes a DateTime to render a calendar. I want to pass in the DateTime from my ViewData using ‘dot notation’ for MVC.
Edit 2
I heard/seen that some MvcContrib projects might have this capability, but I can’t seem to find it again.
There is no way to resolve this – only workarounds. You cannot include Value types as TModel in ViewUserControl as TModel has a constraint to be a reference type.
The easy workaround is to wrap your value type in a class as your model.
By defining your own class like MyModel above, you can now pass a DateTime to your views, like so
Your view of course will need to define MyModel as it’s model type, like so
And inside your View, simply refer to the DateTime property to access the DateTime.