i did not understand ,what you want to make me understand was working fine,can you create example for me plz.or where i am making mistake
namespace MvcBasic.Controllers
{
public class tbl_Designation
{
public int Design_ID { get; set; }
public string Design_Name { get; set; }
}
public class BasicFormsController : Controller
{
private List<tbl_Designation> tbl_Designations;
public BasicFormsController()
{
tbl_Designations = new List<tbl_Designation>()
{
new tbl_Designation()
{
Design_ID = 1,
Design_Name = "Hello"
},
new tbl_Designation()
{
Design_ID = 2,
Design_Name = "World"
},
new tbl_Designation()
{
Design_ID = 3,
Design_Name = "Foo"
},
new tbl_Designation()
{
Design_ID = 4,
Design_Name = "Bar"
},
};
}
// GET: BasicForms
[HttpGet]
public ActionResult Index()
{
ViewBag.Design_ID = new SelectList(tbl_Designations.AsEnumerable(), "Design_ID", "Design_Name");
return View();
}
[HttpPost]
public ActionResult Index(tbl_Designation model)
{
ViewBag.Design_ID = new SelectList(tbl_Designations.AsEnumerable(), "Design_ID", "Design_Name");
return View(model);
}
}
}
@model MvcBasic.Controllers.tbl_Designation
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>ViewModel</h4>
<hr />
<div class="form-group">
<div class="col-md-10">
<div class="checkbox">
@Html.DropDownList("Design_ID", null, "Select Designation", htmlAttributes: new { @class = "form-control", @id = "select2-1" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Submit" class="btn btn-default" />
</div>
</div>
</div>
}