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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:17:25+00:00 2026-05-18T02:17:25+00:00

I have a rather complex model that I am using to render a form

  • 0

I have a rather complex model that I am using to render a form and perform validation using the model’s meta information meta information.

The View Model has a list of child objects that are included in the form. the child objects are based on this:

[Table]
public class FieldInstance
{
    [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
    public long fiID { get; set; }
    [Column]
    public string fiLabel { get; set; }
    [Column]
    public bool fiIsRequired { get; set; }

    [DisplayName("alpha-numeric value")]
    [Column]
    public string fiStrValue { get; set; }

    [DisplayName("date/time value")]
    [Column]
    public DateTime? fiDateTimeValue { get; set; }

    [DisplayName("integer value")]
    [Column]
    public long? fiIntValue { get; set; }

    [DisplayName("decimal value")]
    [Column]
    public decimal? fiDecValue { get; set; }
    [Column]
    public int fiOrder { get; set; }
    [Column]
    public long fiStreamEntryID { get; set; }  // FK
    [Column]
    public long fiFieldTypeID { get; set; }    // FK

    // Relationship (many FieldInstances to one StreamEntry)
    // using EntityRef<StreamEntry> and ThisKey
    // which is "This" table's FK
    private EntityRef<StreamEntry> _StreamEntry;
    [System.Data.Linq.Mapping.Association(Storage = "_StreamEntry", ThisKey = "fiStreamEntryID")]
    public StreamEntry StreamEntry
    {
        get { return this._StreamEntry.Entity; }
        set { this._StreamEntry.Entity = value; }
    }

    // Relationship (one FieldInstance to one FieldType)
    // using EntityRef<FieldTypes> and ThisKey
    private EntityRef<FieldTypes> _FieldType;
    [System.Data.Linq.Mapping.Association(Storage = "_FieldType", ThisKey = "fiFieldTypeID")]
    public FieldTypes FieldTypes
    {
        get { return this._FieldType.Entity; }
        set { this._FieldType.Entity = value; }
    }

I’m using an Html.EditorFor() statement to render the partial view template for each item in the list.

If I put text into a Datetime field, then Html.ValidationSummary() shows:

•The value 'asd' is not valid for date/time value.
•The value 'asd' is not valid for date/time value.

My problem is that errors are being added to the ModelState twice instead of just once. This is the controller action:

    [HttpPost]
    public ActionResult EntryEdit(StreamEntry form)
    {
        // Get values
        StreamEntry entry = 
            form.seID == 0
            ? new StreamEntry()
            : genesisRepository.GetEntryByID(form.seID);

        // Get Stream for new entry
        if (form.seID == 0)
            entry.Stream = genesisRepository.GetStreamByID(form.StreamID);

        //Validate
        TryUpdateModel(entry);

        if (ModelState.IsValid)
            return RedirectToAction("EntryList", new { id = entry.StreamID });
        else
            return View(entry);
    }

Why are errors that are triggered by the presence of incorrect input resulting in two instances of the error being added to the `ModelState?

  • 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-18T02:17:25+00:00Added an answer on May 18, 2026 at 2:17 am

    They are added once by the default model binder when it tries to parse the StreamEntry form action argument and a second time when you call the TryUpdateModel method on the same type (StreamEntry). So either use action arguments or the TryUpdateModel method but never both. Personally I always use action parameters and never the TryUpdateModel method.

    So to fix the error in your case:

    [HttpPost]
    public ActionResult EntryEdit(StreamEntry model)
    {
        if (!ModelState.IsValid)
        {
            // the model was not valid => redisplay the form so that 
            // the user can fix errors
            return View(model);
        }
        // Remark: might need to load the model's corresponding stream
        // from the repository if its values weren't posted
    
        // the model was valid => update it in the database
        genesisRepository.Update(model);
        return RedirectToAction("EntryList", new { id = model.StreamID });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window that contains several rather complex views. Right now, I'm using
I have a rather complex form in the way that the number of form
I have a number rather large, complex xml documents that I need to loop
I have a PHP class that stores a complex multidimensional array, and rather than
I have a legacy class that is rather complex to maintain: class OldClass {
I have a rather complex legacy ASP.Net application that is under continuous development, and
I have a set of rather complex ORM modules that inherit from Class::DBI .
I have a complex view model which contains a collection of other objects which
I want to implement a rather complex CurveEditor that has to support the usual
I have a rather complex database, where we are using Linq to SQL. I'm

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.