c# - Html.Action not work -
i want bring partial view of question link list edit view. however, when select groupby value, shows error below. please guide me.
the model item passed dictionary of type 'system.collections.generic.list
1[<>f__anonymoustype4
2[surveytool.models.surv_question_ext_model,surveytool.models.surv_question_model]]', dictionary requires 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 = r in db.surv_question_ext_model join s in db.surv_question_model on r.qext_question_id equals s.question_id s.question_survey_id == survey_id group new { r, s } r.qext_language 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 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 returned group of linq query, it's anoumous type, not 1 expecting.
Comments
Post a Comment