如何通过过滤 MVC 中的一个特定字段来在列表中创建两个新字段?

How Can I Create two new fields in a list by filtering the one specific field in MVC?

我有一个 ViewModel 作为:

public class ApplicationContentViewModel
{
    public BPMSPARS.Models.MySql.application application {get; set;}
    public BPMSPARS.Models.MySql.content content { get; set; }
    public BPMSPARS.Models.MySql.app_delegation app_delegation { get; set; }
}

另一方面,我想在视图中创建一个列表:

@foreach (var item in Model)
{
    i++;
    <tr>
        <td>@i</td>
        <th>
           @item.content.CON_VALUE
           //where CATEGORY="TASK"
        </th>
        <th>
            @item.content.CON_VALUE
            //where CATEGORY="PRO_TITLE"
        </th>
        <th>@item.application.APP_CREATE_DATE</th>
        <th>@User.Identity.Name.Split('-')[0]</th>
    </tr>
}

实际上我想在不同条件下的两列中显示一个字段 ( @item.content.CON_VALUE)

首先,我使用这个查询,但它不能 return 第一个 @item.content.CON_VALUE 并且我不能为一个字段(在两列中)应用两个条件。

public ActionResult ProcessList()
{ 
   var db1 = new wf_workflowEntities();
   ApplicationContentViewModel APVM = new ApplicationContentViewModel();

   var ViewModel = (from APP in db1.application
                    join app_del in db1.app_delegation on APP.APP_UID equals app_del.APP_UID
                    join Con in db1.content on APP.PRO_UID equals Con.CON_ID
                    where Con.CON_ID == APP.PRO_UID && app_del.APP_UID == APP.APP_UID && Con.CON_CATEGORY == "PRO_TITLE"
                    select new ApplicationContentViewModel
                    {
                        app_delegation = app_del,
                        application = APP,
                        content = Con,
                    }).AsEnumerable();

    return View(ViewModel);
}

你知道一个合适的解决方案吗?

如果我理解正确,您应该从查询中删除此条件:

&& Con.CON_CATEGORY == "PRO_TITLE"

这样它将 select 同时 PRO_TITLE 和 TASK。然后在你的 cshtml:

   <th>
       @(item.content.CON_CATEGORY=="TASK"?item.content.CON_VALUE:"")
    </th>
    <th>
        @(item.content.CON_CATEGORY=="PRO_TITLE"?item.content.CON_VALUE:"")
    </th>

当类别为TASK(else空白)时,第一列显示CON_VALUE,如果是PRO_TITLE(else),第二列显示CON_VALUE空白)。