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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:48:06+00:00 2026-06-09T10:48:06+00:00

I have an ASP.NET MVC3 application that uses entities generated from a database. Each

  • 0

I have an ASP.NET MVC3 application that uses entities generated from a database. Each entity has also has a separate partial class that uses the MetadataType attribute to associate each entity with a class that is decorated with a number of validation attributes (see below).

[MetadataType(typeof(Drawing.Metadata))]
public partial class Drawing
{
    private sealed class Metadata
    {
        [Required]
        [StringLength(50, MinimumLength = 3, ErrorMessage = "Drawing numbers must be between {2} and {1} characters in length.")]
        [DisplayName("Drawing number")]
        public string Number { get; set; }

        [Required]
        [StringLength(255, MinimumLength = 3, ErrorMessage = "Drawing titles must be between {2} and {1} characters in length.")]
        public string Title { get; set; }
    }
}

My controller code looks like this:

[HttpPost]
public ActionResult Create(Drawing drawing)
{
    if (ModelState.IsValid)
    {
        // Save to database here...
        return RedirectToAction("Index");
    }
    else
    {
        return View(drawing);
    }
}

I have used the Visual Studio templates to create the views to add, edit and delete the entities (The designer code has not been altered).

The problem I am having is that when I create an entity, validation only works if I have client side validation enabled. If I turn off the client side validation then ModelState.IsValid always seems to return true and returns me to the index page.

Can anyone provide any suggestions on how to get server side validation working with Entity Framework entities?

UPDATE:

It seems this question is similar to mine. The author of this post seems to have solved the problem but rather unhelpfully omitted to mention how they fixed the problem…

  • 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-09T10:48:07+00:00Added an answer on June 9, 2026 at 10:48 am

    I found another solution to this problem. Because I didn’t really want to set my properties to nullable I added the following:

    [DisplayFormat(ConvertEmptyStringToNull = false)]
    

    Adding the following annotation to your model property fixes the error as well.

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

Sidebar

Related Questions

I have an ASP.NET MVC3 application that I have built and it has two
I have an ASP.NET MVC 3 (using Entity Framework 4.2) application that uses transactions
I have an ASP.NET MVC 3 application that uses the Ninject.MVC3 extension to setup
I have a ASP.NET MVC3 application that gets a List of Coordinates from a
In my ASP.NET MVC3 application I have the following method that use EF entities
I have to develop an ASP.NET MVC3 application in C# and Razor that has
I have an asp.net mvc3 C# application. It uses a database. The database supports
I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file
We have a ASP.NET MVC 3 application that uses unobtrusive jQuery validation. The page
We have an ASP.Net MVC3 application that is running on Azure, connecting to a

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.