Is there an accepted way to render an EditorTemplate using RenderPartial?
I put a lot of work into an EditorTemplate that would use JQuery UI autocomplete to let the user choose from a list of companies. (It uses an HTML helper to ensure the right JS libraries and CSS rules are included in the "right" places in the generated web page.)
While building another page for that same application, I found I wanted to use that template again, outside the model I built the EditorTemplate for.
This code accomplishes the task, but in a way I can only consider a hack.
@using(Html.BeginForm()) {
ViewData.TemplateInfo.HtmlFieldPrefix = "CompanyName";
Html.RenderPartial("~/Views/Shared/EditorTemplates/Company.cshtml", string.Empty);
<input type="submit" value='Filter' />
}
Because I'm not using EditorFor, there is no "name" parameter, so the rendered input field is just the HtmlFieldPrefix of "CompanyName". The autocomplete works, and I can submit the form and filter the data. But this solution feels sloppy and fragile. Anyone have a better idea?