결과를 필터링하는 데이 @Html.DropDownListFor
을 사용하려고합니다.IEnumerable '에'Type '에 대한 정의가 없습니다.
컨트롤러 :
[HttpGet]
public ActionResult Leading()
{
ReportClassHandle ReportClassHandle = new ReportClassHandle();
return View(ReportClassHandle.LeadingAll());
}
그리고 LeadingAll
방법은 다음과 같습니다
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"]),
});
}
는 Leading View
가 완료 내 :
@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>
내 Leading Model
:
나는이 코드를 실행, 오류를 던지고있다 :
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?)
이 나를 인도 해주십시오.
으로 변경하십시오.이보기를 반환하는 컨트롤러 코드를 표시하십시오. 내 생각 엔 IEnumerable 모델 유형을 반환하지 않는다는 것입니다. –
귀하가 주장하는 것은 단순히 가능하지 않습니다. 뷰의 모델은'@model IEnumerable'이지만 메시지는 명확하게'Leading' ('IEnumerable'이 아니라)이라고 말하고 있습니다. 그리고 만약 그것이'@model IEnumerable '이면'
@CraigW를 표시하지 않았습니다. [이 오류] (https://stackoverflow.com/questions/40373595/the-model-item-passed-into-the-dictionary-is-http : –