在查看MVC两列和值

问题描述 投票:1回答:1

我想从两列值求和我得到的,这些值是从视图页面收集的数据添加基于客户从数据库中的控制器,从而增加它不是一种选择,因为据我所知,我可能是错的任何帮助将不胜感激。

我可以分别得到两列的总和,但不能得到两列的总和。

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.PkgBasePrice)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Description)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.BasePrice)
        </th>
    </tr>

    @foreach (var item in Model.Where(ModelItem => 
ModelItem.CustomerId.Equals(Session["CustomerId"])))
    {
    <tr>

        <td>
            @Html.DisplayFor(modelItem => item.PkgBasePrice)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Description)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.BasePrice)
        </td>

    </tr>
    }

</table>
<h2>
    Package Total: [email protected](c => 
c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.PkgBasePrice)

</h2>
<h2>
    Product Total: [email protected](c => 
c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.BasePrice)

</h2>

我想获得PkgBasePrice和BasePrice的总和一个量

asp.net-mvc
1个回答
0
投票

既然你已经有了要合并两个单独的资金,你可以添加你在一起如下两个款项:

@(@Model.Where(c => c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.PkgBasePrice) + 
    @Model.Where(c => c.CustomerId.Equals(Session["CustomerId"])).Sum(b => b.BasePrice))
© www.soinside.com 2019 - 2024. All rights reserved.