ASP.NET MVC 4 映射和数据汇总

问题描述

我制作了这个 MVC 控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace Project1.Controllers
{
    public class Report2Controller : Controller
    {

        private static BLL.Reports _portal;
        private static String _reportID;
        private Domain.Reports _report;

        static Report2Controller()
        {
            _portal = new BLL.Reports();
        }

        public ActionResult Index(String reportID,String reportName)
        {
            _reportID = reportID;
            ViewBag.ReportName = reportName;
            return View();
        }

        public async Task<JsonResult> ReadReport2([DataSourceRequest] DataSourceRequest request)
        {
            DataSourceResult result = null;
            try
            {
                _report = await _portal.ReadReport2(_reportID);
                result = _report.ToDataSourceResult(request);
            }
            catch (Exception err)
            {
                result = new DataSourceResult()
                {
                    Errors = err.Message
                };
            }
            return new JsonResult { Data = result,MaxJsonLength = Int32.MaxValue };
        }
    }
}

在视图中,我希望在加载页面时运行报告。

而且我不确定如何在 Index.cshtml 页面调用它。

请参阅 .DataSource .Read 部分:

<div id="historyPanel" class="panel panel-default bottomPanelMargin">
    <div class="panel-heading">
        <h3 class="panel-title">Reports</h3>
    </div>
    <div class="panel-body">
        @(Html.Kendo().Grid<Report2>()
            .Name("grid")
            .DataSource(dataSource => dataSource
                .Ajax()
                .ServerOperation(false) // Paging,sorting,filtering and grouping is done client side
                .Read(read => read.Action("ReadReport2","Report2Controller"))
                .PageSize(15)
                .Events(e1 => e1.Error("onError")))
            .AutoBind(false)
            .Columns(c => {
                c.Bound(o => o.Column1).Title("Column 1");
                c.Bound(o => o.TypeEmp).Title("Employee Type");
                c.Bound(o => o.Column3).Title("Column 3");
                c.Bound(o => o.Column4).Title("Column 4");
                c.Bound(o => o.Column5).Title("Column 5");
                c.Bound(o => o.Column6).Title("Column 6");
            })
            .sortable()
            .Resizable(resizable => resizable.Columns(true))
            .Pageable()
            .Scrollable(s => s.Enabled(true).Height("auto"))
            .Events(e => e.DataBound("onDataBound"))
            .ToolBar(x => x.Custom().Text("Export").HtmlAttributes(new { href = "#",id = "export" }))
            .norecords(x => x.Template("<div><span class='empty-span' style='font-weight: bold; padding: 1em; line-height: 3em;'></span></div>")))
    </div>
</div>

我认为下面的 onDataBound 部分将是我计算员工类型中不同条目数量的最佳位置(临时员工数量、承包商数量、全职员工数量和其他员工数量) ):

function onDataBound(e) {
   var emptySpan = $('.empty-span');
   emptySpan.text('');

   for (var i = 0; i < this.columns.length - 1; i++) {
     this.autoFitColumn(i);
   }

   var records = e.sender.dataSource.total();
     if (records == 0) {
       emptySpan.text('No Data Found');
     }
   }
  1. 如何在页面加载时运行此报告?控制器的索引返回一个视图,所以我设置了索引视图的元素来显示数据。

  2. 我如何计算不同的员工类型?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)