Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 35599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:15:40+00:00 2026-05-10T14:15:40+00:00

The html helper methods check the ViewDataDictionary for a value. The value can either

  • 0

The html helper methods check the ViewDataDictionary for a value. The value can either be in the dictionary or in the Model, as a property. To extract the value, an internal sealed class named the ViewDataEvaluator uses PropertyDescriptor to get the value. Then, Convert.ToString() is called to convert the object returned to a string.

Desired code in Controller action

The controller action should only populate the Model, not format it (formatting the model is global).

Desired code in View

The view can render a HTML textbox and extract the string representation of the property with this line of code:

 <%=Html.TextBox(“Date”) %> <%=Html.TextBox(“Time”) %> <%=Html.TextBox(“UnitPrice”) %> 

Binding Model’s Property to HtmlHelper.TextBox()

For the textbox’s value, the UnitPrice property’s value from the model instance is converted to a string. I need to override this behavior with my own conversion to a string, which is per property – not per type. For example, I need a different string representation of a decimal for UnitPrice and another string representation of a decimal for UnitQuantity.

For example, I need to format the UnitPrice’s decimal precision based on the market.

 string decimalPlaces = ViewData.Model.Precision.ToString (); <%=Html.TextBox(“UnitPrice”, ViewData.Model.TypeName.UnitPrice.ToString('N' + decimalPlaces)) %> 

2-way databinding please

Just like the IModelBinder is the Parse for each property of the model, I need a Format for each property, kinda like Windows Forms binding, but based on the model instead of the control. This would enable the model to round-trip and have proper formatting. I would prefer a design where I could override the default formatting. In addition, my model is in a separate assembly, so attributed properties specifying a formatter are not an option.

Please note I need property specific formatting for a model, not type specific formatting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:15:41+00:00Added an answer on May 10, 2026 at 2:15 pm

    There’s no way to specify a format with the helpers themselves. The approach you’ve taken will work. Another approach is to add the value pre-formatted into the ModelState.

    EDIT: Are you sure you even want to format a text input with the currency? For example, what you would see in the input is:

    <input type='text' name='UnitPrice' value='$1.23' /> 

    When you post that back to the server, we won’t understand it. Instead, I’d put the currency symbol outside of the text input. For example:

    $<%= Html.TextBox('UnitPrice') %> 

    I’m sure there’s an easy method to render ‘$’ without hard-coding it so it’s localizable, but I don’t know what it is offhand.

    EDIT AGAIN A comment from a developer on my team:

    Well, to be fair, this isn’t that bad. Often when you format a number or a date it’s still understandable coming back in. For example, padding a number (like a ZIP code) to 5 digits, padding a decimal to the hundredths, formatting a date to be yyyy-mm-dd, etc. will come in just fine. Adding extra characters like currency symbols will break, but normally input fields don’t take or display currency symbols anyway – it’s implied.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 211k
  • Answers 211k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The easiest way should be to just try to convert… May 12, 2026 at 10:09 pm
  • Editorial Team
    Editorial Team added an answer In this case, begin is just the name of a… May 12, 2026 at 10:09 pm
  • Editorial Team
    Editorial Team added an answer django-grappelli provides this as one of the features. Here's the… May 12, 2026 at 10:09 pm

Related Questions

I'm building an ActionFilter to reuse some code for a simple spam block -
All I'm trying to do is spec how a one line helper method for
I use the following HTML helper to generate check box: <%= Html.CheckBox(DeluxeFeature)%> Now I
I have a sql server table with 2 fields, ID (primary key) and Name

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.