I am have filled a ViewData["ParamTypes"] object with a selectlist items and now using it in dropdownlistfor so upon submitting a form a value being selected in the list should also be sent to the string parameter ParamNo but it doesn't work. It says the paramNo should also be of selectlistitem type.
@Html.DropDownListFor(model => model.ParamNo, (IEnumerable<SelectListItem>) ViewData["ParamTypes"] )
Controller:
[HttpGet]
public ActionResult DoubleEntryVoucher() //
{
try
{
clsDoubleEntryViewModel v = new clsDoubleEntryViewModel();
v.DetailsList = new List<clsDoubleEntryViewModel>();
ViewData["ParamTypes"] =
new List<SelectListItem>()
{
new SelectListItem{Text= "All", Value="0"},
new SelectListItem{Text= "Invoice No", Value="0"},
new SelectListItem{Text= "ChequeNo", Value="0"},
new SelectListItem{Text= "Voucher No", Value="0"},
};
v.Role_ID = LoginUserRoleID;
return View(v);
}
catch (Exception ex)
{
ShowMessage(MessageBox.Error, OperationType.Error, ex.Message);
return View();
}
}
Model:
public string ParamNo { get; set; }
view:
@using (Html.BeginForm())
{
//@Html.AntiForgeryToken()
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-body">
<div class="col-md-4">
<div class="form-group">
@Html.Label("Parameter Type", htmlAttributes: new { @class = "control-label" })
@Html.DropDownListFor(model => model.ParamNo, (IEnumerable<SelectListItem>) ViewData["ParamTypes"] )
</div>
</div>
<div class="col-md-4">
<div class="form-group">
@Html.Label("Param", htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(Model => Model.ParamNo, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
</div>
<div class="box-footer">
<input type="submit" value="Search" class="btn btn-success btnMarginRight pull-right" />
</div>
</div>
</div>
</div>