tags:

views:

144

answers:

2

I have a date time picker combination in a edit template that can be used like Html.EditorFor(x => x.ETA) but now I want to use the same template somewhere where I don't have a model that contains a DateTime property. So I tried Html.Editor("DateWithTime", "Arrival") which uses the correct template, but doesn't assign a value to ViewData.ModelMetadata.PropertyName which is something that my template relies on. It sets the id of the textbox which is obviously important.

Is there a way to render the template and assign a id value to the ViewData.ModelMetadata.PropertyName so I can re-use the logic in the template instead of having to copy it?

A: 

You can use the UIHint in your model. give it the name of the template you want to use

[UIHint("DateWithTime")]

You still use EditorFor with this.

Cheddar
I am not using a model at all in this case, I just have a static for where I want to reuse the same editor template
Mark Nijhof
A: 

Maybe use ViewData.TemplateInfo.HtmlFieldPrefix instead of ViewData.ModelMetadata.PropertyName. I am not sure but I thought that HtmlFieldPrefix an PropertyName have the same value as long as you do not iterate a collection.

You can modify the HtmlFieldPrefix property with the htmlFieldName parameter from Html.Editor.

n26