Как вызвать DropDownList по вашему мнению в MVC.
Сначала измените метод, чтобы он возвращал объект, а не представление:
public List<mstrClient> getCountry()
{
mstrClient objClientList = new mstrClient();
DataSet ds = new DataSet();
string sQuery = "SELECT * FROM INV_mstrCountry WHERE CStatus = 'Y'";
SqlDataAdapter da = new SqlDataAdapter(sQuery, con);
con.Open();
da.Fill(ds);
con.Close();
List<mstrClient> CountryList = new List<mstrClient>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
mstrClient objClient = new mstrClient();
objClient.CountryCode = ds.Tables[0].Rows[i]["CountryCode"].ToString();
objClient.Country = ds.Tables[0].Rows[i]["CountryName"].ToString();
CountryList.Add(objClient);
}
return CountryList;
}
Контроллер:
public ActionResult Create()
{
mstrClient objClient = new mstrClient();
ModelState.Clear();
var list = getCountry();
ViewBag.CountryList = new SelectList(list, "ID_VALUE", "TEXT_ON_DROPDOWNLIST");
return View(objClient);
}
Вид:
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Select a item from the dropdownlist</label>
@Html.DropDownList("CountryList", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
</div>