Using MVC EditorTemplates with Nearforums

Dec 9, 2011 at 8:36 AM

Hi,

I tried to create some standard editing templates to be used with @Html.EditorFor(m = > m.Date) to be used in my own edit cshtmls
So i wanted to add an EditorTemplate for System.DateTime

This gives me the error that Syste.DateTime must be a referencetype to be used as 'TModel' in the BaseViewPage
At first i did not understand what i was doing wrong becasue samples stated that this should work

After some searching i came across the where statement in the BaseViewPage

    public class BaseViewPage<TModel> : WebViewPage<TModel> where TModel : class

I am guessing that when i remove the where class restriction, the editortemplates on struct DateTime should work.

But i am unable to see if i could 'just' remove this and be happy or is this really necessary?
Or does Nearforums have another way to do something simular to the MVC EditorTemplates.

Coordinator
Dec 9, 2011 at 11:02 AM

Hi,

You can remove it, no problem.

Kind Regards,

Jorge

Coordinator
Dec 9, 2011 at 5:44 PM
Edited Dec 9, 2011 at 5:44 PM

Also, instead of removing the TModel constrain, you can make the editor template view to inherit from WebViewPage (overriding default BaseViewPage defined in the Views/web.config file).

Use in the editor template:

@inherits System.Web.Mvc.WebViewPage<DateTime>

 

Regards,

Jorge

Dec 9, 2011 at 6:30 PM

Thanks for the reply.

I ill go for your second suggestion

Thanks again