Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Formatting Field Values - ASP.NET MVC

RSS
Modified on Wed, Jan 11, 2012, 12:24 PM by Administrator Categorized as ASP·NET MVC

Overview

By default, the Html.TextBoxFor method applies no formatting to field values. This article describes how to easily format the data and still have MVC pickup the changes for the view model.

Solution

The default way of creating the textbox, shown below, doesn't format the field value.

<%: Html.TextBoxFor(m => m.Account.Balance)%>

The following code demonstrates how to format field values within an ASPX page on a site that's using MVC.

<%: Html.TextBox("Account.Balance", 
        String.Format("{0:F2}", Model.Account.Balance), 
        new {   id="Account_Balance", 
                style="width:6em;"} )
        %>

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.