Search code examples
c#twitter-bootstrapasp.net-mvc-5mvc-editor-templates

Rendering bootstrap components in EditorTemplates


I have the following property in my QuoteSalesRep class:

[Display(Name = "Commision %")]
[UIHint("Percentage")]
public decimal CommisionPercentage { get; set; } 

I would like to create an Editor template that would render anything with the [UIHint("Percentage")] like so:

enter image description here

Under Views/Shared/EditorTemplates I added Percentage.cshtml. I currently have the following code:

@model decimal

<div class="input-group">
    <input type="text" class="form-control">
    <span class="input-group-addon">%</span>
</div>

I am new to working with templates. What do I need to do to correct the above code so it renders the input-group properly for any property tagged with [UIHint("Percentage")]?


Solution

  • I think all you're missing is a generic way of generating the text input:

    @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue.ToString(), new { @class = "form-control" })