我有以下模型:
public class FacturaIntrareModel
{
private List<DetaliiFacturaIntrareModel> _produse = new List<DetaliiFacturaIntrareModel>();
public List<DetaliiFacturaIntrareModel> Produse
{
get { return _produse; }
set { _produse = value; }
}
}
public class DetaliiFacturaIntrareModel
{
[Range(0, double.MaxValue, ErrorMessage = "The Discount must have positive values!")]
public decimal Discount { get; set;}
}
绑定的代码是这样的:
@model FacturaIntrareModel
@using DevExpress.Data
@Html.DevExpress().GridView(settings =>
{
settings.Columns.Add(col =>
{
col.FieldName = produsId;
col.Caption = "Discount";
col.ColumnType = MVCxGridViewColumnType.Default;
col.SetDataItemTemplateContent
(c =>
{
string idProdus = DataBinder.Eval(c.DataItem, produsId).ToString();
var index = Model.Produse.FindIndex(y => y.IdProdus.ToString() == idProdus);
ViewContext.Writer.Write
(
@Html.TextBoxWithCustomHtmlAttributesFor(x => x.Produse[index].Discount, new { @onchange = "setDiscountProdus(" + idProdus + ", $(this).val())", @style = textBoxWitxh }).ToHtmlString()
+
@Html.ValidationImageWithTooltipFor(x => x.Produse[index].Discount).ToHtmlString()
);
}
);
col.Width = texBoxColWidth;
col.CellStyle.HorizontalAlign = textBoxColAlign;
});
}
).Bind(Model.Produse).GetHtml()
为 DISCOUNT 生成的 html 是:
<input data-type="decimal" id="Produse_1__Discount" name="Produse[1].Discount" onchange="setDiscountProdus(2, $(this).val())" style="width:40px;" type="text" value="2">
<div class="field-validation-valid" data-valmsg-for="Produse[1].Discount" data-valmsg-replace="true"></div>
RANGE
没有为注解生成html 注解。