The issue in your code as posted is that your partial view is iterating through a SelectList so "item" is going to be a SelectListItem. You then access "value" and "text"
<option value="@item.value">@item.text</option>
However the proper properties are "Value" and "Text", and c# is case sensitive so you need to change your view to
<option value="@item.Value">@item.Text</option>
One of the problems with using ViewBag is that you don't know what the types are in your view so VS can't help you when you're doing things wrong. You're better ditching the viewbag and use typed models, and you can also stop using the SelectList as that is mainly used for rendering a listbox on the view, whereas you are constructing html manually in a view. If you want to stick with your SelectList then change your view like this;
@model System.Web.Mvc.SelectList
<option value="">-- Select States --</option>
@if (Model != null)
{
foreach (var item in Model)
{
<option value="@item.Value">@item.Text</option>
}
}
Now VS knows what type "item" is and lets you use intellisense and tells you if you use the wrong properties. Now change the controller;
public ActionResult GetState(int CountryID)
{
List<State_list> states = GetStateList().Where(x => x.CountryID == CountryID).ToList();
SelectList stList = new SelectList(states, "StatelistID", "STATE", "CountryID");
return PartialView("DisplayState", stList);
}
You can improve this even more by getting rid of the SelectList altogether. The view;
@model List<ChaBuss.Models.State_list>
<option value="">-- Select States --</option>
@if (Model != null)
{
foreach (var item in Model)
{
<option value="@item.StatelistID">@item.STATE</option>
}
}
Controller;
public ActionResult GetState(int CountryID)
{
List<State_list> states = GetStateList().Where(x => x.CountryID == CountryID).ToList();
return PartialView("DisplayState", states);
}