2

This is my code:

@Html.DropDownList("Locate", new List<SelectListItem>
{
    new SelectListItem {Text = "Luxor", Value="1"},
    new SelectListItem {Text = "Abu Simbel Airport", Value="2"},
    new SelectListItem {Text = "Other", Value="3"}
},"Select Location")

what I need is, when user select a list item, how to pass the selected item to controller. because data load is change according to selected list item.like below in controller.

if (Value == "1")
{
    return View(cp);
}
else
{
    return View(cp1);
}
ekad
  • 14,436
  • 26
  • 44
  • 46
  • What do you pass as parameters to your controller action? Do you pass a model? Do you pass specific values? Is this an ajax request (if yes please post boht the relevant js code and the controller action method code). – Christos Nov 17 '15 at 06:22
  • it seems to be the duplicate of [How to get DropDownList SelectedValue in Controller in MVC4](http://stackoverflow.com/questions/27901175/how-to-get-dropdownlist-selectedvalue-in-controller-in-mvc4) – Shaharyar Nov 17 '15 at 06:51

1 Answers1

0

The easiest way to do achieve this is to POST data to server, where you send entire form content, along with your drop down list selection. To achieve this, just add a submit button. Please note that drop down list may only send simple data types. In order to obtain this value after the POST, you need to adjust your controller like below:

[HttpPost]
public void Mycontroller(string Locate)
{//do something with data}
Мitke
  • 310
  • 3
  • 17