[英]Html.Action not work
我想将问题链接列表的部分视图带到我的编辑视图中。 但是,当我选择groupby值时,它显示以下错误。 请指导我。
传递到字典中的模型项的类型为'System.Collections.Generic.List
1[<>f__AnonymousType4
2 [SurveyTool.Models.SURV_Question_Ext_Model,SurveyTool.Models.SURV_Question_Model]]',但此字典需要类型为'的模型项System.Collections.Generic.IEnumerable`1 [SurveyTool.Models.SURV_Question_Ext_Model]'。
编辑视图:
@model IFXSurveyTool.Models.SURV_Main_Model
<div class="question">
<h2>Link</h2>
@Html.Action("QuestionLink", "SURV_Main", new { Survey_ID = Model.Survey_ID })
</div>
控制器:
public ActionResult QuestionLink(int Survey_ID)
{
var query = from r in db.SURV_Question_Ext_Model
join s in db.SURV_Question_Model on r.Qext_Question_ID equals s.Question_ID
where s.Question_Survey_ID == Survey_ID
group new { r, s } by r.Qext_Language into grp
select grp.FirstOrDefault();
return PartialView(query.ToList());
}
QuestionLink视图:
@model IEnumerable<SurveyTool.Models.SURV_Question_Ext_Model>
<br />
<table class="strip">
@foreach (var item in Model)
{
<tr>
<td width="5%"></td>
<td>
@Html.ActionLink("QuestionLink", "Edit", "SURV_Answer", new { Language = item.Qext_Language }, null)
</td>
</tr>
}
</table>
请在您的PartialView代码中更改以下行:
@model IEnumerable<SurveyTool.Models.SURV_Question_Ext_Model>
至:
@model List<SurveyTool.Models.SURV_Question_Ext_Model>
或在控制器中返回类型。 类型需要匹配。
从注释:还返回了一组LINQ查询,因此它是无名的Type,而不是您期望的类型。
你没有什么错误。 尝试这个:
@model IEnumerable<SurveyTool.Models.SURV_Question_Ext_Model>
<br />
<table class="strip">
@foreach (var item in Model)
{
<tr>
<td width="5%"></td>
<td>
@Html.ActionLink("Edit", "QuestionLink", "SURV_Answer", new { Language = item.Qext_Language }, null)
</td>
</tr>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.