Look, How i am passing the DropdownList
selected value to Controller Post Method.
I have add only necessary Codes here, Please follow this to get your Dropdown value.
Controller
[HttpGet]
public ActionResult Index()
{
AccountModel account = new AccountModel();
account.accountStatusList= ObjContext.Status.ToList();
return View(account);
}
Custom Model Class
public class AccountModel
{
public int selectedStatusId { get; set; }
public List<Status> accountStatusList { get; set; }
}
View
@model Nop.Models.AccountModel
@using (Html.BeginForm("Index", "ControllerName", FormMethod.Post))
{
<div class="row-fluid span12">
<div class="span3">
<p><strong>Account Status :</strong></p>
</div>
<div class="span5">
// Bind the dropdown by List.
@Html.DropDownListFor(model => model.selectedStatusId, new SelectList(Model.accountStatusList, "StatusId", "StatusName"), "--Select--")
</div>
</div>
<div class="row-fluid span12">
<button class="btn btn-inverse" type="submit" title="Search for Account"><span class="fa fa-search"> Search</span></button>
</div>
}
Controller Post Method
[HttpPost]
public ActionResult Index(AccountModel account)
{
int selectedID = account.selectedStatusId; // You can find your selectedID here..
return View(account);
}
See ViewBag vs Model.