Ok so I got my dropDown box going, I have my options and if I select any, I want to write the submitted selected item's value, sounds easy right? well every time I click any option and submit it, the value is displayed on the URL, but I cant seem to write it out...
View (Index.cshtml):
<p>Dropdown Using viewbag with Html.DropDownList </p>
<br/>
<div>
@using (Html.BeginForm("dropDown", "Home", FormMethod.Get))
{
@Html.DropDownList("ListItem")
<button type="submit"></button>
}
</div>
<p>@ViewBag.SelectedValue</p> //should print the value I selected but it does nothing...
Controller (HomeController.cs):
public ActionResult Index()
{
List<SelectListItem> ObjItem = new List<SelectListItem>()
{
new SelectListItem {Text="Select",Value="0",Selected=true },
new SelectListItem {Text="ASP.NET",Value="1" },
new SelectListItem {Text="C#",Value="2"},
new SelectListItem {Text="MVC",Value="3"},
new SelectListItem {Text="SQL",Value="4" },
};
ViewBag.ListItem = ObjItem;
return View("Index");
}
public ActionResult dropDown(List<SelectListItem> ListItem)
{
ViewBag.SelectedValue = ListItem[0].Value; //crossing fingers this has the value I want to print
return this.View("Index");
}