Textboxfor不显示字符串格式 [英] Textboxfor not showing the string format

查看:102
本文介绍了Textboxfor不显示字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我已经为它进行了以下初始投资代码

型号代码



 [DataType(DataType.Currency)] 
[必需(ErrorMessage = < span class =code-string>需要初始投资)]
[DisplayFormat(ApplyFormatInEditMode = true ,DataFormatString = {0:C})]
[显示(名称= 初始投资)]
[RegularExpression( < span class =code-string> ^ [1-9] + [0-9] * $,ErrorMessage = 初始投资是数字)]
public string InitialInvestment { get ; set ; }





Aspx代码



<%:Html.TextBoxFor(InitialInvestment => Model.InitialInvestment。,new {@class =textbox,style =width:105px,maxlength =15})%> 





但这不是以货币格式显示



请帮我解决问题



谢谢

解决方案

,ErrorMessage = 初始投资为数字)]
public string InitialInvestment { get ; set ;}





Aspx代码



<%:Html.TextBoxFor(InitialInvestment => Model.InitialInvestment。,new {@class =textbox,style =width:105px,maxlength =15})%> 





但这不是以货币格式显示



请帮我解决问题



谢谢


你错误地使用了Lambda表达式在文本框中



替换



<%:Html.TextBoxFor(InitialInvestment => Model.InitialInvestment。,new {@class =textbox,style =width:105px,maxlength =15})%> 





with



<%:Html.TextBoxFor(m => m.InitialInvestment,new {@class = textbox,style =width:105px,maxlength =15})%> 





现在尝试以上格式,你应该让它运行。







你甚至不需要使用注释。删除

 DisplayFormat(ApplyFormatInEditMode =  true ,DataFormatString =   {0:C})] 

并写下以下内容



 @ Html.TextBoxFor(model => model.InitialInvestment,new {@class =textbox,id =InitialInvestment,Value = String.Format({0:C},Model.InitialInvestment)})


Hi Friends,

I have put it the following code for the initial investment
Model code

[DataType(DataType.Currency)]
[Required(ErrorMessage = "Initial investment is required")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:C}")]
[Display(Name = "Initial Investment")]
[RegularExpression("^[1-9]+[0-9]*$", ErrorMessage = "Initial investment is numeric")]
public string InitialInvestment { get; set; }



Aspx code

<%: Html.TextBoxFor(InitialInvestment => Model.InitialInvestment., new { @class = "textbox", style = "width:105px", maxlength = "15"})%>



but this is not displaying in currency format

Please help me to solve the issue

Thanks

解决方案

", ErrorMessage = "Initial investment is numeric")] public string InitialInvestment { get; set; }



Aspx code

<%: Html.TextBoxFor(InitialInvestment => Model.InitialInvestment., new { @class = "textbox", style = "width:105px", maxlength = "15"})%>



but this is not displaying in currency format

Please help me to solve the issue

Thanks


You have the wrong usage of Lambda Expressions in Textbox

Replace

<%: Html.TextBoxFor(InitialInvestment => Model.InitialInvestment., new { @class = "textbox", style = "width:105px", maxlength = "15"})%>



with

<%: Html.TextBoxFor(m=>m.InitialInvestment , new { @class = "textbox", style = "width:105px", maxlength = "15"})%>



Now try the above format, you should get it running.

OR

You even dont need to use annotations for that. Remove

DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:C}")]

and write the following

@Html.TextBoxFor(model => model.InitialInvestment, new { @class = "textbox", id = "InitialInvestment", Value=String.Format("{0:C}",Model.InitialInvestment) })


这篇关于Textboxfor不显示字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆