mvc-editor-templateshtml-editor

Html Editor Template


I have a editor template DisplayConfig. In DisplayConfig

@model  string

<input id="@(Model)_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
<input id="@(Model)" class="DisplayTypeConfigurator" type="checkbox" />

I want to call this template in my view and send string so i get different id for every textbox. In my view

@Html.Editor("Tab_Info_Product", "DisplayConfig")

I do not want to send the value through my model. I want the result like

<input id="Tab_Info_Product_DisplayOrder" class="DisplayTypeConfigurator" type="number" />

Solution

  • You should use @Html.IdForModel() to construct the ids of your <input> tags.

    <input id="@Html.IdForModel()_DisplayOrder" class="DisplayTypeConfigurator" type="number" />
    <input id="@Html.IdForModel()" class="DisplayTypeConfigurator" type="checkbox" />