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 8201253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:44:43+00:00 2026-06-07T06:44:43+00:00

I currently have: @Html.EditorFor(model => model.PurchasePrice) I would like to split this into 2

  • 0

I currently have:

@Html.EditorFor(model => model.PurchasePrice)

I would like to split this into 2 separate fields separated by a decimal (for price input obviously). But if I do that using basic text boxes I will loose the ability to take advantage of ASP.NET’s validation.

Is there a way to do this, in Razor or by using attributes, so that I am able to keep the JS and server-side validation against my Entity model?

I can easily do it somewhere else by creating my own functions within the viewmodel, but I’m new to MVC3 and not entirely sure if that would be the best route or there is a simpler method.

Edit:

This is kind of the direction I am thinking, I do not fully understand how this works.

I set 2 fields, 1 as ppDollar and 1 as ppCents. In the controller I have:

modelname.PurchasePrice = Request["ppDollar"] + Request["ppCent"];

But, I can look at that and tell that’s not going to work. So, I guess the question really is how is user input validated against the entity model and how can I better take advantage of the built in functionality?

  • 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. Editorial Team
    Editorial Team
    2026-06-07T06:44:45+00:00Added an answer on June 7, 2026 at 6:44 am

    You can create custom editors for particular types that are rendered by EditorFor. You can find a lot of examples of how to do this online, most of them focusing on a custom DateTime editor but the same idea applies to any type. Just one example from a quick search:

    http://buildstarted.com/2010/09/10/overriding-displayfor-and-editorfor-to-create-custom-outputs-for-mvc/

    In short, the process is:

    • Create a partial view template, placed in the Views\Shared\EditorTemplates folder, with the same name as the type (e.g. Decimal.cshtml).
    • The view should use, as its model, the type you want to display: @inherits System.Web.Mvc.WebViewPage<System.Decimal>
    • Make the view display whatever you want, using some field naming convention or whatever.
    • You can also pass HTML attributes via the appropriate EditorFor overload, referenced in your template through the ViewData.ModelMetadata.AdditionalValues property.

    One thing to note: once you define an editor template it will be used for every call to EditorFor. You can scope them to a specific controller by moving the EditorTemplates folder into the appropriate view subfolder instead of the shared one.

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

Sidebar

Related Questions

I am currently using the Html.EditorFor<> method for generating editor fields, however I would
I have a model that looks something like this: public class SampleModel { public
I currently have html markup stored in xsl and xml. This has previously enabled
How would you implement this ? I have the following model : class Something
I have two editor templates: UploadFiles.cshtml: @model HttpPostedFileBase[] @Html.EditorFor(m => Model, UploadFile, new {
I currently have a huge HTML file which doesn't have line breaks and just
I currently have the following CSS (called splash.css): html { background:url(splash.jpg) center no-repeat; background-size:auto
I currently have two apps: app1/ app2/ templates/ app1.html app2.html In app1.html, I'm including
I currently have the following MySQL statement to replace the HTML entity for a
I currently have a product view page that contains an MVCContrib HTML Grid with

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.