I wrote a simple mock your question.
It can work. The simple code is on DropDownController
Here is the Source Code,I Upload to github.
ViewModel
public class DropDownViewModel
{
[Display(Name = "Dealer")]
public int? DealerIdRef { get; set; }
public IEnumerable<SelectListItem> Ddllist { get; set; }
}
Index View
Mock Your Submit action
@model Sample.Models.DropDownViewModel
@using (Html.BeginForm("ShowDDL", "DropDown", FormMethod.Post))
{
@Html.DropDownListFor(model => model.DealerIdRef, Model.Ddllist, " Select Dealer ", new { @class = "form-control" })
<button>Submit</button>
}
ShowDDL View
Show your select data.
@model Sample.Models.DropDownViewModel
<b>Your Select Value: </b> @Model.DealerIdRef
DropDownController
public ActionResult Index()
{
DropDownViewModel model = new DropDownViewModel()
{
Ddllist = GetDDL(),
DealerIdRef = 1
};
return View(model);
}
[HttpPost]
public ActionResult ShowDDL(DropDownViewModel viewModel)
{
return View(viewModel);
}
private IEnumerable<SelectListItem> GetDDL()
{
return new List<SelectListItem>()
{
new SelectListItem()
{
Text = "One",
Value = "1"
},
new SelectListItem()
{
Text = "Two",
Value = "2"
}
};
}