Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

javascript - ASP.NET MVC 4 mapping and data summary

I've made this MVC Controller:

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 };
        }
    }
}

In the View, I want the Report to run when the page is loaded.

And I'm not sure how to call it in the Index.cshtml page.

See the .DataSource .Read section:

<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>

I am thinking that the onDataBound section below would be my best spot to count the number of distinct entries in the employee type (number of temps, number of contractors, number of full-time, and number of others):

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. How would I get this report to run when the page is loaded? The Controller's Index returns a View, so I have set the Index view's element to show the data.

  2. How would I count the distinct employee types?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...