0
我无法使用EditorFor,因为我的输入具有其他一些属性,如readonly
,disable
和class
因此,我为TextBoxFor使用了扩展名。我需要显示格式的数值,所以我的扩展方法被定义为TextBoxFor带格式值的extes显示0
public static MvcHtmlString FieldForAmount<TModel, TValue>(
this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TValue>> expression)
{
MvcHtmlString html = default(MvcHtmlString);
Dictionary<string, object> newHtmlAttrib = new Dictionary<string, object>();
newHtmlAttrib.Add("readonly", "readonly");
newHtmlAttrib.Add("class", "lockedField amountField");
var _value = ModelMetadata.FromLambdaExpression(expression,
htmlHelper.ViewData).Model;
newHtmlAttrib.Add("value", string.Format(Formats.AmountFormat, value));
html = System.Web.Mvc.Html.InputExtensions.TextBoxFor(htmlHelper,
expression, newHtmlAttrib);
return html;
}
Formats.AmountFormat
被定义为"{0:#,##0.00##########}"
。
比方说_value
是2,newHtmlAttrib
示出它作为2.00
但所得html
显示0
,它总是显示0
无论任何价值。 我在哪里错了,或者我能做些什么来修复它?
我不能看到'TextBox'在'HtmlHelper' – bjan
我想你的意思'System.Web.Mvc.Html.InputExtensions。 TextBox(htmlHelper,fullHtmlFieldName,value,htmlAttributes);' – bjan
是的,它的工作。我可以知道为什么'TextBoxFor'接受htmlAttributes但不使用它的'value'属性? – bjan