I am trying to display list of items from database based on dropdownlist
selection which is hard coded in ASP.NET MVC application.
My Controller
public ActionResult ListofItems()
{
ListofClassClassHandle listofClassClassHandle = new ListofClassClassHandle ();
return View(listofClassClassHandle.LeadingAll());
}
ListofClassClassHandle
Class
public List<Leading> LeadingAll()
{
clsUtilities clsUtilities = new clsUtilities();
DataSet ds;
List<Leading> leading = new List<Leading>();
string sSQL;
sSQL = "exec GetLeading 'NZ'";
ds = clsUtilities.GetDataSet(sSQL);
DataTable dataTable = ds.Tables[0];
foreach(DataRow dr in dataTable.Rows)
{
leading.Add(
new Leading
{
RankId = Convert.ToInt32(dr["RankId"]),
Name = Convert.ToString(dr["Name"]),
}
);
}
Leading
Class
public class Leading
{
public int RankId { get; set; }
public string Name{ get; set; }
public Countries AllCountries { get; set; }
}
public enum Countries
{
New_Zealand,
Australia
}
Leading
View
@Html.DropDownList("AllCountries",
new SelectList(Enum.GetValues(typeof(Countries))),
"Select Country",
new { @class = "form-control", style = "width: 150px;" })
<table class="table">
<tr>
<th>
@Html.DisplayName("Rank")
</th>
<th>
@Html.DisplayName("Name")
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.RankId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
</tr>
}
</table>
I want to display the list based on dropdown country list selection. The dropdown list is hard coded where the list of data is populating from database.
Please guide me. I do not have any idea how to accomplish this? Any help or guidance is highly appreciated.