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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:17:24+00:00 2026-06-12T14:17:24+00:00

I am using ADO.Net entity framework with asp.net mvc3. I have a model which

  • 0

I am using ADO.Net entity framework with asp.net mvc3. I have a model which is database first. The data validation does not work in some cases, as I will explain.

I have a form, when I submit that form, some items are being validated while others are not. I am simply using a form like this,

    @using (Html.BeginForm()) {
    @Html.ValidationSummary(true)


   <fieldset>
        <legend></legend>


         <div class="editor-label">
            @Html.LabelFor(model => model.VERSION_ID)
            @Html.EditorFor(model => model.VERSION_ID)
            @Html.ValidationMessageFor(model => model.VERSION_ID)
        </div>

        <div class="editor-field">
            @Html.LabelFor(model => model.ENTITY2.Name)
            @Html.EditorFor(model => model.ENTITY2.Name)
            @Html.ValidationMessageFor(model => model.ENTITY2.Name)
        </div>
    <p>
        <input type="submit" value="Create" />
    </p>

Now, the version_id has validation working while the Name does not. I am getting the name from another entity. Any ideas on why the validation is not working? I can input empty fields which should not be allowed as that field is required, but when i press submit i get an error.

  • 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-12T14:17:25+00:00Added an answer on June 12, 2026 at 2:17 pm

    I think your Model class is allowing empty values.

    I would avoid using the Model classes directly in Views and create a separate ViewModel (a POCO class) for that. The ViewModel should have only relevant properties which the view requires. Not all the Properties of domain model most of the time !. you can use data annotations on the ViewModel( Required attribute etc…)

    public class VersionViewModel
    {
      [Required]
      public string VersionID { set;get;}
    
      [Required]
      public string Name { set;get;}
    }
    

    Your View will be strongly typed to this ViewModel. When posted back to the action method, you will map the values from the ViewModel fo your domain model and save it.

    [HttpPost]
    public ActionResult Edit(VersionViewModel model)
    {
      if(ModelState.IsValid)
      {
         //validation is ok. Let's save
        var domainModel=new Version();
        domainModel.VERSION_ID=model.VersionID ;
        domainModel.Name=model.Name;
    
        //Let's save and REdirect 
        yourRepositary.SaveVersion(domainModel);
        return RedirectToAction("Saved",new { id=model.ID});     
      }
      return View(model);
    }
    

    Instead of manually mapping, you may consider using the libraries like AutoMapper.

    • 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 w/ ado.net entity framework doing some validation. I have
I'm building a data model using ADO.NET Entity Framework 3.5 in Visual Studio 2008
I'm building an ASP.NET MVC site using the ADO.NET Entity Framework. I have an
I have a asp.net application in that I am using ado.net entity framework in
I am using the ADO.NET Entity Framework data model. I send data from SQL
General Info: ASP.NET MVC app using ADO.NET Entity Framework SQL Server 2005 I have
in our current project we are using ADO.NET Entity Framework as data layer for
I have an app using the ADO.NET entity framework (the VS2008 version, not the
I'm using an ADO.NET Entity Model which I'm trying to query using LINQ. The
I'm using ADO.NET entity framework, and am using an AdventureWorks database attached to my

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.