the dropdownlist does not work, I need to choose an option and depending on the selection go to a page. I have this code but the post method does not work.
controller
public ActionResult Country()
{
List<SelectListItem> li = new List<SelectListItem>();
li.Add(new SelectListItem { Text = "Select", Value = "0" });
li.Add(new SelectListItem { Text = "A", Value = "1" });
li.Add(new SelectListItem { Text = "B", Value = "2" });
ViewData["country"] = li;
return View(li);
}
post method
[HttpPost]
public ActionResult Country(List<SelectListItem> li)
{
foreach(SelectListItem lis in li )
{
if (lis.Value == "0")
{
return View();
}
if (lis.Value == "1")
{
return RedirectToAction("Option", "AS");
}
if (lis.Value == "2")
{
return RedirectToAction("Option", "AP");
}
}
return View();
}
view
@using (Html.BeginForm("Country", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.DropDownList("country", ViewData["country"] as List<SelectListItem>)
<input type="submit" value="GO" class="btn btn-info" />
please help, regards