I am trying to use this @Html.DropDownListFor
for filtering the results.
Controller:
[HttpGet]
public ActionResult Leading()
{
ReportClassHandle ReportClassHandle = new ReportClassHandle();
return View(ReportClassHandle.LeadingAll());
}
And LeadingAll
method is:
public List<Leading> LeadingAll(string Type)
{
clsUtilities clsUtilities = new clsUtilities();
DataSet ds;
List<Leading> leading = new List<Leading>();
string sSQL;
SqlParameter[] prms = new SqlParameter[1];
sSQL = "exec GetLeading @Type";
prms[0] = new SqlParameter("@Type", SqlDbType.VarChar);
prms[0].Value = Type;
ds = clsUtilities.CreateCommandwithParams(sSQL, prms);
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"]),
});
}
My complete Leading View
is:
@model IEnumerable<ReportProject.Models.Leading>
@using (Html.BeginForm("Leading", "Home", FormMethod.Post))
{
@Html.DisplayFor(m => m.Type)
@Html.DropDownListFor(m => m.Type, new List<SelectListItem> {
new SelectListItem{ Text="General", Value="1" },
new SelectListItem{Text="Advance", Value="2"}}, "Please select")
@Html.ValidationMessageFor(m => m.Type, "", new { @class = "error" })
}
<table class="table table-striped">
<tr>
<th>@Html.DisplayName("Rank")</th>
<th>@Html.DisplayName("Name")</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.RankId)</td>
<td>@Html.DisplayFor(modelItem => item.Name)</td>
</tr>
}
</table>
My Leading Model
:
public class Leading
{
public int RankId { get; set; }
public string Name { get; set; }
[Required(ErrorMessage = "Type is Required")]
public string Type { get; set; }
}
When I run this code, it is throwing error:
Compiler Error Message: CS1061: 'IEnumerable<Leading>' does not contain a definition for 'Type' and no extension method 'Type' accepting a first argument of type 'IEnumerable<Leading>' could be found (are you missing a using directive or an assembly reference?)
Please guide me.