用2个不同的值分组,并在Razor视图中显示



我有2个问题列表和1个问题有2种语言,我想显示2个动作链接语言的问题行,如果它有。但我不知道如何显示另一种语言在一排。我只能显示一种语言。

有任何提示或指导吗?

db。SURV_Question_Model数据:

__________________________________________
Survey ID |    Question_ID    | Qext_Text | 
==========================================
1         |       1           |  Q1       |          
2         |       2           |  Q2       |               
==========================================

db。SURV_Question_Ext_Model数据:

___________________________________________________
| Quext_Question_ID | Qext_Text | Qext_Language |
===================================================
|       1           |  Q1       |     ENG       |
|       1           |  Q1       |     GER       |
|       2           |  Q2       |     ENG       |
===================================================

我想在Razor视图中显示的内容:

__________________________________________________
Quext_Question_ID | Qext_Text | Qext_Language     |
===================================================
       1           |  Q1       |     ENG | GER    |
       2           |  Q2       |     ENG          |
===================================================

我的控制器:

public ActionResult SURV_Main_Details_QuestionList(int Survey_ID)
        {
            List<QuestionLinkListViewModel> viewmodel = new List<QuestionLinkListViewModel>();
            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_Question_ID into grp
                        select grp.FirstOrDefault();
            foreach (var item in query)
            {
                viewmodel.Add(new QuestionLinkListViewModel()
                {
                    Survey_ID = Survey_ID,
                    Question_ID = item.r.Qext_Question_ID,
                    QuestionText = item.r.Qext_Text,
                    Languages = item.r.Qext_Language,
                });
            }
            return PartialView(viewmodel);
        }

My Razor View:

@using (Html.BeginForm())
{
    <table class="strip">
        for (int i = 0; i < Model.Count(); i++)
        {
            <tr>
                <td></td>
                <td width="70%">
                    @Model[i].QuestionText
                </td>
                <td>
                    @Html.ActionLink(Model[i].Languages, "SURV_Question_Edit", "SURV_Question", new { Question_ID = Model[i].Question_ID, Languages = Model[i].Languages }, new { @class = "popup-link2" }) 
                    @Html.Raw(" ")
                    @Html.ActionLink(Model[i].Languages2, "SURV_Question_Edit", "SURV_Question", new { Question_ID = Model[i].Question_ID, Languages = Model[i].Languages2 }, new { @class = "popup-link2" }) 
                </td>
            </tr>
            }
    </table>
}

我通过在查询中添加查询来修复它:

public ActionResult SURV_Main_Details_QuestionList(int Survey_ID)
        {
            List<QuestionLinkListViewModel> viewmodel = new List<QuestionLinkListViewModel>();
            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_Question_ID into grp
                        select grp.FirstOrDefault();
            foreach (var item in query.ToList())
            {
                var queryLang = 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 r.Qext_Question_ID == item.r.Qext_Question_ID
                                select s;
                if (queryLang.Count() == 1)
                { 
                    viewmodel.Add(new QuestionLinkListViewModel()
                    {
                        Survey_ID = Survey_ID,
                        Question_ID = item.r.Qext_Question_ID,
                        QuestionText = item.r.Qext_Text,
                        Languages = item.r.Qext_Language,
                        Languages2 = " " 
                    });
                }
                else if(queryLang.Count() == 2)
                {
                    viewmodel.Add(new QuestionLinkListViewModel()
                    {
                        Survey_ID = Survey_ID,
                        Question_ID = item.r.Qext_Question_ID,
                        QuestionText = item.r.Qext_Text,
                        Languages = "ENG",
                        Languages2 = "GER"
                    });
                }
            }
            return PartialView(viewmodel);
        }

相关内容

  • 没有找到相关文章

最新更新