开发者

Formatting TextboxFor content

I have this :

@Html.TextBoxFor(m => m.MyClass.MyValue, new { style = "width: 138px", id = "mTextBox", 开发者_开发知识库maxlength = 10 })

I'd like format the content. Where can I do this ?

Thanks,


This worked for me..

@Html.TextBoxFor(model => model.INVOICE_DATE,"{0:MM/dd/yyyy}", new { maxlength = 10, style = "min-height:30px; min-height: 30px;  border-color: green; " })


You can Use

Html.TextBox("MyValue",String.Format('<your format>',Model.MyClass.MyValue))

for example "{0:d}" or "{0:c}" or if you want to use only Html.TextBoxFor then u can format your content from model.


I've used EditorFor in a case such as this and decorated my property with DisplayFormat attribute

in my view:

<%: Html.EditorFor(model => model.StartDate)%>

and on my view model

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime StartDate { get; set; }


You can also do it, setting only the format string: TimeSpan Format Strings

@Html.TextBoxFor(model => model.Fecha, "{0:G}", new { @class="vld-required" })


for example to display the TimeStamp in ShortDate+ShortTime ("3/9/2010 4:15 PM")

Html.TextBoxFor(model => model.MyClass.TimeStamp, String.Format("{0:g}",Model.MyClass.TimeStamp))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜