0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.