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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:12:53+00:00 2026-06-01T20:12:53+00:00

In my MVC3 application I have the model ( not important properties deleted ):

  • 0

In my MVC3 application I have the model ( not important properties deleted ):

public class AccountViewModel
{
    [StringLength(65)]
    public string Property1 { get; set; }

    [StringLength(65)]
    public string Property2 { get; set; }
}

The problem is when an action is submited validation attribute called twice, and I can get 4 errors in summary, instead of 2:

'Property1' length must be less than 65 characters
'Property1' length must be less than 65 characters
'Property2' length must be less than 65 characters
'Property2' length must be less than 65 characters

I dont use Validate method in my controller’s code. The problem appears also with my custom attributes, but its not happens with Required attribute. Also I have to note that ctor of the custom attributes also called twice

My action

[HttpPost]
public ActionResult CreateOrEdit(AccountViewModel model) {

    if (!ModelState.IsValid) {
        return View("Edit", model);
    }

    try {
        _accountService.InsertOrUpdate(model);

    }
    catch (Exception ee) {
        ModelState.AddModelError("", ee.Message);
        return View("Edit", model);
    }

    return RedirectToAction("Index");
}

On View I render my errors using:

@{
    var errors = ViewData.ModelState.Errors();
    <div class="alert alert-block alert-error @(errors.Count == 0 ? "hide" : "")" > 
    <h4 class="alert-heading"> You got an error!</h4> 
    <ul>
        @foreach (var error in errors) {
            <li>@error</li>
        }
    </ul>
    </div>
}

And I double re-check once more that ViewData.ModelState already contains errors twice.

  • 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-01T20:12:54+00:00Added an answer on June 1, 2026 at 8:12 pm

    The problem was in integrating Ninject. If you use Ninject.MVC package ( I use version 3 ) it registers his own ModelValidationProvider while initializing and removes the old one:

    In Ninject.Web.Mvc.MvcModule

    this.Kernel.Bind<ModelValidatorProvider>().To<NinjectDataAnnotationsModelValidatorProvider>();
    

    In Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin:

    public void Start()
    {
        ModelValidatorProviders.Providers.Remove(ModelValidatorProviders.Providers.OfType<DataAnnotationsModelValidatorProvider>().Single());
        DependencyResolver.SetResolver(this.CreateDependencyResolver());
        RemoveDefaultAttributeFilterProvider();
    }
    

    So, rather than creating my own implementation of IDependencyResolver ( Ninject Kernel wrapper ) I followed this tutorial
    or
    you should remove Ninject.MVC package and remove its binaries from the bin folder.

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

Sidebar

Related Questions

In my MVC3 application, I have a queries class specific to each controller that
I am creating an ASP.NET MVC3 application using NHIBERNATE. I have a base class
I have an employee class in model for ASP.NET MVC3. There is a field
In my MVC3 application, I have a view model that I Json encode so
In an MVC3 application I have a view rendering two Ajax partial views: a
I have a MVC3 application with some XML files on the App_Data folder. To
I have been working on mvc3 application and trying to localize the same. I
I have a ASP.NET MVC3 application that handles time-consuming processes (copying a large file
I am working on an MVC3 application using the Razor syntax and I have
I am using SignalR in my MVC3 application, and since I have implemented StructureMap

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.