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

  • Home
  • SEARCH
  • 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 8347831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:29:38+00:00 2026-06-09T07:29:38+00:00

I am using ASP.NET MVC3 and EF 4.1 I have two DropDownList in my

  • 0

I am using ASP.NET MVC3 and EF 4.1
I have two DropDownList in my Model, It is required and not duplicated too.
And I want the Remote validate function: ValidateDuplicateInsert get firing when user submit data. But I can NOT get the ValidateDuplicateInsert function firing.
Where am I wrong?

My Model

    [Key]
    public int CMAndOrgID { get; set; }

    [Display(Name = "CM")]
    [Required(ErrorMessage = "CM is required.")]
    [Remote("ValidateDuplicateInsert", "CMAndOrg", HttpMethod = "Post", AdditionalFields = "CMID, OrganizationID", ErrorMessage = "CM is assigned to this Organization.")]
    public int? CMID { get; set; }

    [Display(Name = "Organization")]
    [Required(ErrorMessage = "Organization is required.")]
    public int? OrganizationID { get; set; }

    public virtual CM CM { get; set; }
    public virtual Organization Organization { get; set; }

The ValidateDuplicateInsert function in my CMAndOrg controller

    [HttpPost]
    public ActionResult ValidateDuplicateInsert(string cmID, string orgID)
    {
        bool flagResult = true;
        foreach (CMAndOrg item in db.CMAndOrgs)
        {
            if (item.CMID.ToString() == cmID && item.OrganizationID.ToString() == orgID)
            {
                flagResult = false;
                break;
            }
        }
        return Json(flagResult);
    }

And my View

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>CMAndOrg</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.CMID, "CM")
    </div>
    <div class="editor-field">
        @Html.DropDownList("CMID", String.Empty)
        @Html.ValidationMessageFor(model => model.CMID)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.OrganizationID, "Organization")
    </div>
    <div class="editor-field">
        @Html.DropDownList("OrganizationID", String.Empty)
        @Html.ValidationMessageFor(model => model.OrganizationID)
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
}
  • 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-09T07:29:40+00:00Added an answer on June 9, 2026 at 7:29 am

    There is a bug in MVC3 related to unobtrusive validation on dropdownlist. Please reference to this http://aspnet.codeplex.com/workitem/7629%5B^] link for more detail explaination.

    Briefly, you can’t use the same name for category collection and category field, so just change your collection name and update following line in your view

    @Html.DropDownList("CategoryID", String.Empty)
    

    with this

    @Html.DropDownListFor(model => model.CategoryID, new SelectList((System.Collections.IEnumerable)ViewData["Categories"], "Value", "Text"))
    

    Thanks again Henry He

    Original link
    http://www.codeproject.com/Articles/249452/ASP-NET-MVC3-Validation-Basic?msg=4330725#xx4330725xx

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

Sidebar

Related Questions

I'm developing a dashboard using ASP.NET MVC3 and need to have two divs which
I am using ASP.NET MVC3 with EF Code First. I have not worked previously
I had created a webpage using asp.net mvc3 razor. I have two master pages
I have a website developed using ASP.NET MVC3. I now want to expose a
I am using asp.net Mvc3 I have 2 controllers in two different projects. HomeController
Using asp.net MVC3, I have a partial view which requires remote validation. As I
I am creating an ASP.NET MVC3 application using NHIBERNATE. I have a base class
I have a MVC3 ASP.NET Project in which I am using jQuery and KendoUI
I have an employee class in model for ASP.NET MVC3. There is a field
Using: ASP.NET MVC3 Ninject 2 Fluent nHibernate I have 2 databases (DB1 & DB2).

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.