Form Returns the same checkbox values ​​on subsequent submit action in MVC

I followed the suggestion in this question ...

[ How to handle checkboxes in ASP.NET MVC forms?

... to set multiple checkboxes with the same name = "..." attribute and the form behaves as expected FIRST submission time. Subsequent form submissions use the original array of Guid values ​​instead of properly submitting a new array of marked element values.

The relevant code in the view ...

 <% foreach (ItemType itemType in ViewData.Model.ItemTypes) %>
        <%{ %>
        <li>
            <input id="selectedItems" name="selectedItems" type="checkbox" value="<%= itemType.Id%>" />
            <%= itemType.Description %></li>
        <%} %>

      

This creates a series of checkboxes, one for each element with a value = "..." attribute set to the Id of the element.

Then in my controller action, the method signature ...

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SelectItems(Guid[] selectedItems)
{...}

      

The first time through the method, the selected array of elements correctly holds the Guid for each selected element. But subsequent form submissions will always contain whatever was first selected in the original submit action, no matter what changes you make to what it checked before submitting the form. This doesn't seem to have anything to do with my code, as checking the selectedItems array that the MVC framework passes to the method reveals that the framework seems to always be repeating the same value over and over again.

Close the browser, launch it again, select a different original checkbox to submit, and the process will start over and over again (the originally selected checkboxes are always the one in the selectedItems argument).

Suppose I should be fat and ignore some form value caching with the framework, but I would swear it wasn't in Preview 5.

Driving me nuts and probably a simple problem; any ideas ????

0


source to share


2 answers


FWIW, here's what I'm doing (not sure if it's related):

  // please MS, stop screwing around!!!!!!!!!!!!!!!
  string r = Request.Form["r"];

      



Then move on to manually fetching values ​​from "r". I am still using Preview 4 as they did indeed break too many existing features rather than fix the error messages.

+1


source


I'm not sure what is causing your problem, but I have a WAG ...

Are you using RedirectToAction in your mail method?



[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SelectItems(Guid[] selectedItems)
{
  /* lol snip */
  return RedirectToAction("WhateverActionIsTheGetVersionOfThisPostAction");
}

      

This could mean resetting something in the background ... Again, wild ass ...

0


source







All Articles