下面的代码工作正常,但在文本框中的十进制值具有此格式“0,0000”
(,是小数分隔符)。我想只有两个十进制。我如何做到这一点?
(,是小数分隔符)。我想只有两个十进制。我如何做到这一点?
谢谢,
//Database model used with NHibernate public class Bank { public virtual int Id { get; set; } public virtual string FirstName { get; set; } public virtual string LastName{ get; set; } public virtual decimal Amount { get; set; } } //MVC Model public class MyModel { public Bank Bank { get; set; } } //View @Html.TextBoxFor(m => m.Bank.Amount,new { id = "tbAmount"})
更新1
在调试器中,我没有看到任何小数,wehn我一步一步地在里面(o @ HTML.Textbofor)的视图,该值没有任何小数,但是当页面显示有4个小数
//Database model used with NHibernate public class Bank { public virtual int Id { get; set; } public virtual string FirstName { get; set; } public virtual string LastName{ get; set; } public virtual decimal Amount { get; set; } } //Class for view public class ViewBank { [displayFormat(DataFormatString = "{0:n2}",ApplyFormatInEditMode = true)] public decimal Amount { get; set; } } //MVC Model public class MyModel { public Bank Bank { get; set; } var ViewBank = new ViewBank() { Amount = Bank.Amount}; } //View @Html.TextBoxFor(m => m.Amount,new { id = "tbAmount"})
更新2
我做了一个小工作例子:http://goo.gl/RKtwY
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。