I have a DataTable which looks like below:
TOTAL_CODE COD_NAME
AP0001 School
AP0002 Hospital
AP0003 Airport
AP0004 House
I am very new to ASP.NET MVC3 and I cannot figure it out how to bind a DataTable to my DropDownListFor control.
PS: I have model as below:
@model Kery.Models.Profile
@{
ViewBag.Title = "DetailAdd";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<P>Please select your sex type: @Html.DropDownListFor(..............)</p>
Model:
public class Profile
{
public IEnumerable<SelectListItem> SexList { get; set; }
}
Controller:
[HttpGet]
public ActionResult DetailAdd()
{
System.Data.DataTable _dtJikchaekList = _bp.DtReturnS(false
, "CHP_AJAX_CODEHELPER"
, "JJ"
, ""
, "0"
);
return View();
}
this is one way to do it.
On your controller
on your view