简体   繁体   中英

Html.Action not work

i want to bring the partial view of question link list to my edit view. However, when i select the groupby value, it shows the error below. Please guide me.

The model item passed into the dictionary is of type 'System.Collections.Generic.List 1[<>f__AnonymousType4 2[SurveyTool.Models.SURV_Question_Ext_Model,SurveyTool.Models.SURV_Question_Model]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[SurveyTool.Models.SURV_Question_Ext_Model]'.

Edit view:

@model IFXSurveyTool.Models.SURV_Main_Model

    <div class="question">

            <h2>Link</h2>

            @Html.Action("QuestionLink", "SURV_Main", new { Survey_ID = Model.Survey_ID })

        </div>

Controller:

 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 view:

@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>

Please change following line in Your PartialView code:

@model IEnumerable<SurveyTool.Models.SURV_Question_Ext_Model>

to:

@model List<SurveyTool.Models.SURV_Question_Ext_Model>

Or returning type in controller. Types needs match.

From comments: there is also returned group of LINQ query, so it's anoumous Type, not the one You expecting.

You have little error. Try this:

@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>
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM