Hi @reddy reddy,
string format:A string that is used to format the input.
https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.html.inputextensions.textbox?view=aspnet-mvc-5.2
Let me give two examples so that you can understand it more intuitively.
If you need the value of the text box to have two decimal places, you can specify the format as "{0:N2}".
@Html.TextBox("Name", Model.name, "{0:N2}", new { style = "color:green" })
public int name { get; set; }
public ActionResult Index()
{
Table1 table1= new Table1();
table1.name = 1603;
return View(table1);
}
Before use:
After use:
If you need a specific date format:
@Html.TextBox("Name", Model.name, "{0:dd/MM/yyyy}", new { style = "color:green" })
public DateTime name { get; set; }
public ActionResult Index()
{
Table1 table1= new Table1();
DateTime date1 = new DateTime(2023, 12, 25);
table1.name =date1;
return View(table1);
}
Before use:
After use:
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.