2

I have dropdown which is used for displaying pagesize in view. example as

@Html.DropDownListFor(m => m.PageSize,
new List<SelectListItem>() { new SelectListItem() { Text = "10" }, 
new SelectListItem() { Text = "20" },
new SelectListItem() { Text = "50" },
new SelectListItem() { Text = "100" }
})

I have to get the selected item value inside controller action.

my action will accept only get call. I just don't want to pass as query string. so how to achieve this?

dove
  • 20,469
  • 14
  • 82
  • 108
Vetrivel mp
  • 1,214
  • 1
  • 14
  • 29
  • Try using Post requests. see http://stackoverflow.com/questions/10187469/pass-selectedvalue-of-dropdownlist-in-html-beginform-in-asp-net-mvc-3 http://stackoverflow.com/questions/10119286/passing-dropdowns-selected-value-from-view-to-controller-in-mvc3 – amesh Oct 26 '12 at 07:43

3 Answers3

2

If you want to pass it using a GET I'm afraid your only option is a query string.

To take a quote from the w3.org spec:

"The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI."

dove
  • 20,469
  • 14
  • 82
  • 108
1

My Idea is prepare this much more dynamic and send data to model.

<td>
@Html.DropDownListFor(m => m.CurrentVoucher, new System.Web.Mvc.SelectList(Model.OutgoingStatusList, "Value", "Text"), new { style = "width:140px" })
</td>

------------
model.OutgoingStatusList = new List<SelectListItem>();
------------
model.KidsList = new List<SelectListItem>();
            for (int i = 0; i <= 20; i++)
                model.KidsList.Add(new SelectListItem { Value = i.ToString(), Text = i.ToString() });

model will get value "m.CurrentVoucher". There is only example (I take this from my notes) and "model.kidsList" you can change to "model.OutgoingStatus" you can change name. Read this example I hope I helped.

Rafał Developer
  • 2,135
  • 9
  • 40
  • 72
1

If your aversion to using a querystring is manually building the url, then wrap it in a form with method="get", that way you can still use controls like the dropdown but they'll automatically be turned into the querystring on submitting the form.

Betty
  • 9,109
  • 2
  • 34
  • 48