在EditorTemplates中渲染引导程序组件

时间:2016-09-19 14:31:51

标签: c# twitter-bootstrap asp.net-mvc-5 mvc-editor-templates

我的QuoteSalesRep课程中有以下属性:

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

我想创建一个编辑器模板,它可以像[UIHint("Percentage")]一样呈现任何内容:

enter image description here

Views / Shared / EditorTemplates 下,我添加了Percentage.cshtml。我目前有以下代码:

@model decimal

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

我是使用模板的新手。我需要做些什么才能纠正上面的代码,以便为使用[UIHint(&#34; Percentage&#34;)标记的任何属性正确呈现输入组?]

1 个答案:

答案 0 :(得分:1)

我认为你所缺少的是生成文本输入的通用方法:

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