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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:59:38+00:00 2026-05-12T08:59:38+00:00

Seeing as though ASP.NET MVC 2 Preview 1 was just released it means the

  • 0

Seeing as though ASP.NET MVC 2 Preview 1 was just released it means the way things are done may be slightly different in terms of the model. The DataAnnotation feature allowing validation to be done against properties in its model is good, but I’m not sure where to put it.

I create my models manually as recommended in Steve Sanderson’s book on ASP.NET MVC, which suits me perfectly. Should I have a separate model, however, for POST data coming from a view page? So say I were creating product items, my main model may look like this:

public class Product {
    [Column(IsPrimaryKey = true, IsDbGenerated = true)] public int ProductID { get; set; }
    [Column] public string ProductName { get; set; }
    [Column] public string ProductDescription { get; set; }
    [Column] public double ProductCost { get; set; }
}

Now Scott’s example gives us DataAnnotations so you can do:

public class Product {
    public int? ProductID { get; set; }

    [Required(ErrorMessage="Must enter a product name!")]
    public string ProductName { get; set; }

    public string ProductDescription { get; set; }

    [Range(1, 500, ErrorMessage="Too expensive!")]
    public double ProductCost { get; set; }
}

The latter example would have a nullable ProductID field because it would be an auto-increment field in the database. Now both of these examples would be contained in classes, and probably with the same name. Personally I don’t think my main model should have these annotations in them as it shouldn’t be their responsibility to validate data. So should I have separate namespaces with classes in them having different roles?

  • 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-12T08:59:38+00:00Added an answer on May 12, 2026 at 8:59 am

    In my opinion validation is part of your model’s concerns – keep them together.

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

Sidebar

Related Questions

I'm jumping into ASP.Net MVC and wanted to know how tough it's been for
The project is developed using ASP.NET MVC framework and heavily relies on .NET 3.5.
I'm interested in seeing what custom extensions other developers have created for the ASP.NET
I'm developing my C# 3.5 ASP.NET MVC web app, same as I do all
I have a strange issue with an Asp.NET MVC application. Using Asp.NET MVC 3
I see IoC and DI mentioned pretty much everywhere for ASP.NET MVC. While I'm
I am using Asp.Net MVC 2, and trying to iterate through the metadata to
In my ASP.Net MVC application I am using IoC to facilitate unit testing. The
I am seeing a special character in the ASP .NET page I am rendering.
After seeing a previous post Making Applications programmed in .NET languages work on older

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.