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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:26:14+00:00 2026-05-13T10:26:14+00:00

I’m trying to figure out the best way to validate data within a MVC

  • 0

I’m trying to figure out the best way to validate data within a MVC C# app and xVal seemed to be the best fit. However I’m running into a problem with data type validation.

At first I was doing an UpdateModel into the DTO and then running the validation on the DTO. This worked great for things like required fields, however UpdateModel would throw an exception if you tried, for example, to map a string (“asd”) into a decimal field. Since UpdateModel had to be ran before there was any data to validate I wasn’t sure how to get around that.

My solution was to create a DTO per form that UpdateModel would copy into, run validation on that, and then copy values out into the proper DTOs. All the attributes on the form DTO would be strings so UpdateModel never bombs out, and I’d enforce the data validation through xVal. However while rules like required are kicking in, I can’t seem to get the DataType rule to kick in (in this case trying DataType.Currency).

I had also tried getting the client-side validation to work, but I was hoping there was a clean way to do server-side validation of data types.

What have others done with regards to validating data types on the server-side?

  • 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-05-13T10:26:14+00:00Added an answer on May 13, 2026 at 10:26 am

    What I ended up doing was creating some DTOs that represent the forms. These DTOs would take a Request.Form in and automatically map all the form values into the internal properties (ex public string email, public string firstname) based on them being the same name as the form values.

    They would have all string properties and I’d put the xVal attributes on them. I’d then use xVal and regular expressions to make sure the data coming in was valid (ex a valid date, email, number, etc). This way there would never be an exception thrown because it was always going into a string, as opposed to .Net trying to parse it into a date or something.

    This would make sure that the data always made it to xVal where I could run the validation I want, and then convert it to the proper type like DateTime once I know I have valid data.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.