c# - LINQ Sql Expression to Return a Sum -


i'm quite new @ asp.net mvc.

with said, i'm trying send view sum of sales acomplished salesman. controller method:

[httppost]     public jsonresult totaldevendas(int vendedor_id)     {          try         {              var resultado = (from vendas in db.tblvenda                        vendas.vendedor_id == vendedor_id                        select vendas.venda_valor).sum();              return json(resultado);         }         catch (exception)         {             return null;         }     } 

and me trying show on list, along other info..

<div class="row"> <div class="col-lg-12">     <table class="table table-hover">         <thead>             <tr>                 <th>cod.</th>                 <th>nome</th>                 <th>total vendido</th>             </tr>         </thead>          <tbody>             @foreach (tblvendedor vendedor in model)             {                  <tr>                     <td>@vendedor.vendedor_id</td>                     <td>@vendedor.vendedor_nome @vendedor.vendedor_sobrenome</td>                     <td><!--chama o método total de vendas, que retorna o valor total de vendas vendedor -->                         @{                             ((vendedorescontroller)this.viewcontext.controller).totaldevendas(vendedor.vendedor_id).tostring();                         }                     </td>                 </tr>             }         </tbody>      </table> </div> 

but result empty column sums's suposed be.

how can make method return sum?


Comments

Popular posts from this blog

Add new key value to json node in java -

javascript - Highcharts Synchronized charts with missing data points -

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -