have a dropdown in my view, couple of other controls and a input button to save the data.
On saving I have ActionReult Save ()
which needs the value I selected in the dropdownlist.
How can I get the selected value of the dropdownlist on my controller Actionresult Save()
View:
------
var docTypes = Model.DocumentTypes.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).AsEnumerable(); @Html.DropDownList("SelectedDocumentType", docTypes, "--select--", new { @class = "ddSelect" })
Model:
-----
public IEnumerable DocumentTypes { get; set; }
Controller:
-----------
[HttpParamAction] [HttpPost] [ValidateInput(false)] public ActionResult Save() { int DocumentType = // I have to assign the selected value of the dropdownlist here }
Dhanunjay JajimogglaPosted Oct 24, 2014, 8:09 AM
Hi Nilufar Parveen,
Try this....
@using (Html.BeginForm("Save", "Controller", FormMethod.Post, null))
{
var DocumentTypes = Model.DocumentTypes.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).AsEnumerable(); @Html.DropDownList("SelectedDocumentType", docTypes, "--select--", new { @class = "ddSelect" })
}