UpdateModel not working consistently for me if a ddl gets hidden by jQuery

Posted by awrigley on Stack Overflow See other posts from Stack Overflow or by awrigley
Published on 2010-02-21T20:01:10Z Indexed on 2010/05/13 17:04 UTC
Read the original article Hit count: 308

Hi

My jQuery code hides a ddl under certain circumstances. When this is the case, after submitting the form, using the UpdateModel doesn't seem to work consistently. My code in the controller:

// POST: /IllnessDetail/Edit
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(IllnessDetail ill)
        {
            IllnessDetailFormViewModel mfv = new IllnessDetailFormViewModel(ill);
            if (ModelState.IsValid)
            {
                try
                {
                    IllnessDetail sick = idr.GetLatestIllnessDetailByUsername(User.Identity.Name);
                    UpdateModel(sick);
                    idr.Save();
                    return RedirectToAction("Current", "IllnessDetail");
                }
                catch
                {
                    ModelState.AddRuleViolations(mfv.IllnessDetail.GetRuleViolations());
                }
            }
            return View(new IllnessDetailFormViewModel(ill));
        }

I have only just started with MVC, and working under a deadline, so am still hazy as to how UpdateModel works. Debugging seems to reveal that the correct value is passed in to the action method:

public ActionResult Edit(IllnessDetail ill)

And the correct value is put into sick in the following line:

IllnessDetailFormViewModel mfv = new IllnessDetailFormViewModel(ill);

However, when all is said, done and returned to the client, what displays is the value of:

sick.IdInfectiousAgent

instead of the value of:

ill.IdInfectiousAgent

The only reason I can think of is that the ddlInfectiousAgent has been hidden by jQuery. Or am I barking up the wrong lamp post?

Andrew

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about jQuery