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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:15:31+00:00 2026-05-29T22:15:31+00:00

I’m having an issue where the model is valid when it creates the HttpGet

  • 0

I’m having an issue where the model is valid when it creates the HttpGet page, but invalid (some properties are null) on the HttpPost.

Here is my call to open the page:

            var quote = new Quote
            {
                Agency = assignedAgency,
                Insured = insured,
                RiskAddress = insured.Address
            };
            db.Quotes.Add(quote);
            db.SaveChanges();

            return RedirectToAction("Edit", "Quote", quote.QuoteID);  

And the HttpGet ActionResult – At this point, the model is valid. Insured and Agency properties are populated and have their respective Address properties populated as well.

    [HttpGet]
    public ActionResult Edit(int quoteID)
    {
        var model = db.Quotes.Find(quoteID);

       return View(model);
    }

And the HttpPort ActionResult – At the entry of this method, the Insured, Agency and their respective Address properties are null, causing an invalid Model state.

    [HttpPost]
    public ActionResult Edit(Quote model)
    {
        if (ModelState.IsValid)
        {
            if (model.SubCosts > 0)
            {
                model.InsuredSubs = true;
                model.SubClassCode = "95626 - Subcontractor - TEST CLASS";
                model.SubClassExposure = model.SubCosts;
            }

            db.Entry(model).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Edit", new { quoteID = model.QuoteID });
        }
        return View(model);
    }

And the HTML:

 @model DomaniOnline.Models.DomaniData.Quote

 @{
     ViewBag.Title = "Classification";
  }

  <h2>General Liability Classification</h2>

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

    @Html.HiddenFor(model => model.QuoteID)
    @Html.HiddenFor(model => model.Insured)
    @Html.HiddenFor(model => model.Insured.Address)
    @Html.HiddenFor(model => model.RiskAddress)
    @Html.HiddenFor(model => model.Agency)
    @Html.HiddenFor(model => model.Agency.Address)

        .
        .
        .
        .
    <p>
        @Html.ActionLink("Back to Insured Info", "Edit", "Insured", new { insuredID = Model.Insured.InsuredID }, null)
        <input type="submit" value="Save & Continue" />
    </p>
</fieldset>
}

I’d like to point out that the “Back to Insured Info” ActionLink at the bottom of the page works just fine and is able to supply the correct model.Insured.InsuredID. But for some reason, when submitting the form to the HttpPost, any property that is of a custom datatype is null. the Html.HiddenFor<> were added as a test while trying to get this to work.

edit: Classes:

 public class Quote
 {
    public virtual int QuoteID { get; set; }
    public virtual Address RiskAddress { get; set; }
    public virtual Agency Agency { get; set; }
    public virtual Insured Insured { get; set; }

    public virtual DateTime PropEffDate { get; set; }
    public virtual bool InsuredSubs { get; set; }
    public virtual int SubCosts { get; set; }
    .
    .
    .
  }
  public class Address
  {
    [Required]
    public virtual string StreetAddress { get; set; }
    [Required]
    public virtual string City { get; set; }
    [Required]
    public virtual string State { get; set; }
    [Required]
    public virtual string ZipCode { get; set; }
  }
  public class Insured
  {
    public virtual int InsuredID { get; set; }
    [Required]
    public virtual string Name { get; set; }
    [Required]
    public virtual Address Address { get; set; }
    public virtual string DBA { get; set; }
    [Required]
    public virtual string BusinessType { get; set; }
    public virtual string Phone { get; set; }
  }
  • 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-29T22:15:34+00:00Added an answer on May 29, 2026 at 10:15 pm

    Your problem is that your using HiddenFor on complex types. This only knows how to render simple types.

    I would suggest either only persisting the ID’s of those objects or using the Html.Serialize helper function from the MVC Futures project to serialize your account and insured objects, then deserialize them in your controller.

    http://weblogs.asp.net/shijuvarghese/archive/2010/03/06/persisting-model-state-in-asp-net-mvc-using-html-serialize.aspx

    Persisting the ID’s should just be the InsuredID, from which you can re-get the Insured and it’s address on postback. The same with Agency.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.