我正在尝试在编辑表单上设置字段格式。我希望它是没有小数的货币格式。
@Html.LabelFor(model => model.Value, htmlAttributes: new { @class = "control-label col-md-3 noleftpadding" })
@Html.EditorFor(model => model.Value, new { htmlAttributes = new { @class = "form-control" } })
我将如何处理?
我也尝试过更改模型,但是当我执行此方法时,每次我尝试编辑另一个字段时,即使我没有故意进行此更改,应用程序也会将现有值重置为null。
[DisplayFormat(DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
public Nullable Value { get; set; }
我发现,如果将ApplyFormatInEditMode设置为false,它不会重置我的值,但是在编辑页面的显示中,当我希望它看起来像没有小数的货币值时,它又返回到十进制值。 / p>
编辑器模板
@ViewBag.Title - My ASP.NET Application@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
var appInsights=window.appInsights||function(config)
{
function r(config){ t[config] = function(){ var i = arguments; t.queue.push(function(){ t[config].apply(t, i)})} }
var t = { config:config},u=document,e=window,o='script',s=u.createElement(o),i,f;for(s.src=config.url||'//az416426.vo.msecnd.net/scripts/a/ai.0.js',u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=['Event','Exception','Metric','PageView','Trace','Ajax'];i.length;)r('track'+i.pop());return r('setAuthenticatedUserContext'),r('clearAuthenticatedUserContext'),config.disableExceptionTracking||(i='onerror',r('_'+i),f=e[i],e[i]=function(config, r, u, e, o) { var s = f && f(config, r, u, e, o); return s !== !0 && t['_' + i](config, r, u, e, o),s}),t
}({
instrumentationKey:'7b294d9c-2c13-4d61-bd3f-65ffb8e1561a'
});
window.appInsights=appInsights;
appInsights.trackPageView();
@RenderBody()
© @DateTime.Now.Year - My ASP.NET Application
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)