【发布时间】:2015-05-05 14:28:40
【问题描述】:
我想查看Edit.cshtml中的表格
我使用Html.Action 从SurveyQuestionController 获取表格,但它显示错误如下:
传入字典的模型项的类型为“System.Collections.Generic.List``1[System.String]”,但此字典需要类型为“System.Collections.Generic.IEnumerable`1”的模型项[SurveyTool.Models.SurveyQuestionModel]'。
我有什么不对吗??
编辑.cshtml:
@model SurveyTool.Models.SurveyModel
<div>
<h2>Link</h2>
@Html.Action("QuestionLink", "SurveyQuestion", new { id = Model.SurveyID })
</div>
SurveyQuestionController.cs:
public ActionResult QuestionLink(string SurveyID)
{
var query = (from r in db.SurveyQuestionModels
where r.SurveyId == SurveyID
select r.QuestionLink).Distinct();
return PartialView(query.ToList());
}
QuestionLink.cshtml:
@model IEnumerable<SurveyTool.Models.SurveyQuestionModel>
<br />
<table class="strip">
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelitem => item.QuestionLink)</td>
</tr>
}
</table>
SurveyQuestionModel.cs:
namespace SurveyTool.Models
{
public class SurveyQuestionModel
{
public int Id { get; set; }
public string QuestionLink { get; set; }
}
}
【问题讨论】:
标签: asp.net-mvc-4 razor