C# 如何使用Kendo Mvc在按钮点击时绑定数据

C# 如何使用Kendo Mvc在按钮点击时绑定数据,c#,asp.net-mvc,kendo-grid,C#,Asp.net Mvc,Kendo Grid,我想在单击搜索按钮时将数据显示到剑道网格中,但它只在浏览器上返回json结果。我在控制台上没有任何错误。我想要的是能够返回剑道网格上的搜索结果。我试着在页面加载时加载数据,它工作正常,但在点击按钮时不起作用 单击按钮时,如何在网格上显示数据 我的观点 <div> </fieldset> @using (Html.BeginForm("SearchNotification", "Notification", FormMethod.Post, new { r

我想在单击搜索按钮时将数据显示到剑道网格中,但它只在浏览器上返回json结果。我在控制台上没有任何错误。我想要的是能够返回剑道网格上的搜索结果。我试着在页面加载时加载数据,它工作正常,但在点击按钮时不起作用

单击按钮时,如何在网格上显示数据

我的观点

 <div>
    </fieldset>
   @using (Html.BeginForm("SearchNotification", "Notification",  FormMethod.Post, new { role = "form" }))
                {

                    <div class="box-footer">
                        <button type="submit" id="btnSearch" class="btn btn-primary">Search</button>
                    </div>

                    <form role="form">
                        <div class="box-body">
                            <div id="divMain" class="col-md-13">
                                <div class="form-group">
                                    @(Html.Kendo().Grid<TTAF.Portal.Parts.Web.Models.NotificationModel.notification>()
                                  .Name("Grid")
                                  .Columns(columns =>
                                  {
                                      columns.Bound(x => x.distributorID).Title("Distributor Code").Width(50);
                                      columns.Bound(x => x.notificationDate).Title("Date").Width(50);
                                      columns.Bound(x => x.notificationType).Title("Type").Width(50);
                                      columns.Bound(x => x.distributorName).Title("Name").Width(50);
                                  })
                                  .AutoBind(false)
                                  .Pageable(pageable => pageable
                                    .Refresh(true)
                                    .PageSizes(true)
                                    .ButtonCount(5))
                                  .Scrollable()
                                  .Filterable()
                                  .Sortable()
                                  .Resizable(resize => resize.Columns(true))
                                  .DataSource(dataSource => dataSource
                                  .Ajax()
                                  .PageSize(10)
                                  .ServerOperation(false)//No post back
                                  .Read(read => read.Action("SearchNotification", "Notification")))) 

                                </div>
                                <br />
                            </div>
                        </div>
                    </form>
                }
            </div>
        </div>
    </fieldset>
</div>

<!--Grid Stylesheet Start-->
<link href="~/Content/Kendo/Kendo-fieldsetStyle.css" rel="stylesheet" />
<link href="~/Content/Kendo/kendo.common.min.css" rel="stylesheet" />
<link href="~/Content/Kendo/kendo.default.min.css" rel="stylesheet" />
<link href="~/Content/Kendo/kendo.rtl.min.css" rel="stylesheet" />
<!--Grid Stylesheet End-->


@section Styles
{
    @Styles.Render("~/bundles/kendo")
    @Scripts.Render("~/bundles/jqueryval")
}

<!--Script Section Start-->
@section Scripts {
    <script src="~/Content/Kendo/js/kendo.all.min.js"></script>
    <script src="~/Content/Kendo/js/kendo.aspnetmvc.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
        });
    </script>

<!--Script Section End-->

@使用(Html.BeginForm(“SearchNotification”、“Notification”、FormMethod.Post、new{role=“form”}))
{
搜寻
@(Html.Kendo().Grid())
.名称(“网格”)
.列(列=>
{
columns.Bound(x=>x.distributorID).标题(“分销商代码”).宽度(50);
列。绑定(x=>x.notificationDate)。标题(“日期”)。宽度(50);
columns.Bound(x=>x.notificationType).Title(“Type”).Width(50);
columns.Bound(x=>x.distributorName).Title(“Name”).Width(50);
})
.AutoBind(假)
.Pageable(Pageable=>Pageable
.刷新(真)
.页面大小(真)
.按钮计数(5))
.Scrollable()
.可过滤()
.Sortable()
.resize可调整大小(resize=>resize.Columns(true))
.DataSource(DataSource=>DataSource
.Ajax()
.页面大小(10)
.ServerOperation(false)//无回发
.Read(Read=>Read.Action(“搜索通知”、“通知”))

} @剖面样式 { @style.Render(“~/bundles/kendo”) @Scripts.Render(“~/bundles/jqueryval”) } @节脚本{ $(文档).ready(函数(){ });
}

控制器

  [HttpPost]
    public ActionResult SearchNotification([DataSourceRequest]DataSourceRequest request, NotificationModel model)
    {

        try
        {
            string jsonReq = ApiBaseUrl + ApiSecuritySubBaseUrl + "/GetDistributorsForAdminUser/" + User.Identity.GetUserId() + "/" + User.Identity.GetUserId();
               string jsonResp = JsonWrapper.JsonGET(jsonReq);

            List<DistributorSimple> ListDistrubutor = Models.DeserialiseFromJson<List<DistributorSimple>>.Deserialise(jsonResp);
            model._ListDistributor = ListDistrubutor;

            List<NotificationProcess> ListNotifiaction = Models.DeserialiseFromJson<List<NotificationProcess>>.Deserialise(jsonResp);
            model._ListNotificationProcess = ListNotifiaction;

            List<string> ListnotificationType = Models.DeserialiseFromJson<List<string>>.Deserialise(jsonResp);
            model._ListNotificationType = ListnotificationType;

            jsonReq = ApiBaseUrl + ApiGeneralSubBaseUrl + "/GetAdminNotificationsByDate";

            JsonParamBuilder myBuilder = new JsonParamBuilder();
            myBuilder.AddParam<string>("submittingUserID", User.Identity.GetUserId().ToString());
            myBuilder.AddParam<string>("userName", User.Identity.GetUserName().ToString());
            myBuilder.AddParam<int>("distributorID", int.Parse(model.SelectedDistributor));
            myBuilder.AddParam<string>("notificationsFromDate", model.DateFrom.ToString("dd/MM/yyyy"));
            myBuilder.AddParam<string>("notificationsToDate", model.DateTo.ToString("dd/MM/yyyy"));
            myBuilder.AddParam<int>("processID", int.Parse(model.SelectedNotificationPrcoess));
            myBuilder.AddParam<string>("notificationType", model.SelectedNotificationType);
            Console.WriteLine("Builder result : " + myBuilder.GetJSonParam());

             string resp = JsonWrapper.JsonPOST(ApiBaseUrl + ApiGeneralSubBaseUrl + "/GetAdminNotificationsByDate", myBuilder.GetJSonParam());
            List<NotificationDetail> _ListNotifications = Models.DeserialiseFromJson<List<NotificationDetail>>.DeserialiseApiResponse(resp);

            List<Models.NotificationModel.notification> listData1 = new List<Models.NotificationModel.notification>();
            foreach (NotificationDetail item in _ListNotifications)
            {
                Models.NotificationModel.notification sngData1 = new Models.NotificationModel.notification();
                sngData1.notificationID = item.notificationID;
                sngData1.notificationMessage = item.notificationMessage;
                sngData1.notificationType = item.notificationType;
                sngData1.processName = item.processName;
                sngData1.notificationDate = item.notificationDate;

                listData1.Add(sngData1);
            }
            NotificationModel.GetAllNotications = listData1;
            return Json(listData1.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
[HttpPost]
公共操作结果搜索通知([DataSourceRequest]DataSourceRequest请求,通知模型)
{
尝试
{
字符串jsonReq=ApiBaseUrl+ApiSecuritySubBaseUrl+“/GetDistributorsForAdminUser/”+User.Identity.GetUserId()+“/”+User.Identity.GetUserId();
字符串jsonResp=JsonWrapper.JsonGET(jsonReq);
List ListDistributor=Models.DeserialiseFromJson.Deserialise(jsonResp);
型号。\u ListDistributor=ListDistributor;
List ListNotifiaction=Models.DeserialiseFromJson.Deserialise(jsonResp);
模型。_ListNotificationProcess=ListNotifiaction;
List ListnotificationType=Models.DeserialiseFromJson.Deserialise(jsonResp);
模型。\u ListNotificationType=ListNotificationType;
jsonReq=ApiBaseUrl+ApiGeneralSubBaseUrl+“/GetAdminNotificationsByDate”;
JsonParamBuilder myBuilder=新的JsonParamBuilder();
myBuilder.AddParam(“submittingUserID”,User.Identity.GetUserId().ToString());
myBuilder.AddParam(“userName”,User.Identity.GetUserName().ToString());
myBuilder.AddParam(“distributorID”,int.Parse(model.SelectedDistributor));
myBuilder.AddParam(“notificationsFromDate”,model.DateFrom.ToString(“dd/MM/yyyy”);
myBuilder.AddParam(“notificationsToDate”,model.DateTo.ToString(“dd/MM/yyyy”);
myBuilder.AddParam(“processID”,int.Parse(model.SelectedNotificationPrcoess));
myBuilder.AddParam(“notificationType”,model.SelectedNotificationType);
WriteLine(“生成器结果:+myBuilder.GetJSonParam());
string resp=JsonWrapper.JsonPOST(ApiBaseUrl+ApiGeneralSubBaseUrl+“/GetAdminNotificationsByDate”,myBuilder.GetJSonParam());
List _ListNotifications=Models.DeserialiseFromJson.DeserialiseAppResponse(resp);
List listData1=新列表();
foreach(列表通知中的通知详细项)
{
Models.NotificationModel.notification sngData1=新模型.NotificationModel.notification();
sngData1.notificationID=item.notificationID;
sngData1.notificationMessage=item.notificationMessage;
sngData1.notificationType=项目.notificationType;
sngData1.processName=item.processName;
sngData1.notificationDate=item.notificationDate;
listData1.Add(sngData1);
}
NotificationModel.GetAllNotification=listData1;
返回Json(listData1.ToDataSourceResult(request),JsonRequestBehavior.AllowGet);
}
捕获(例外情况除外)
{
掷骰子;
}
}
型号

public class NotificationModel
{

    public static List<notification> GetAllNotications { get; set; }
    public class notification
    {
        public int distributorID { get; set; }
        public string distributorName { get; set; }
        public int notificationID { get; set; }
        public string notificationMessage { get; set; }
        public string notificationType { get; set; }
        public int processID { get; set; }
        public string processName { get; set; }
        public DateTime notificationDate { get; set; }

    }
}
公共类通知模型
{
公共静态列表GetAllNotations{get;set;}
公开课通知
{
public int distributorID{get;set;}
公共字符串distributorName{get;set;}
public int notificationID{get;set;}
公共字符串通知消息{get;set;}
公共字符串notificationType{get;set;}
public int processID{get;set;}
公共字符串专业版
<button id="btnSearch"  onclick="myFunction()" class="btn btn-primary">Search</button>    
<script>
function myFunction()
{
   //Remember you used grid name = "Grid"  so in the lines below replace ->
   //"GridName" with whatever grid name you assign   

   //read will request the server and reload only reload datasource
   $('#GridName').data('kendoGrid').dataSource.read();

   //refresh will re-render items in grid from the current datasource
   $('#GridName').data('kendoGrid').refresh();     
}
</script>