简体   繁体   English

将 model 从视图发送到 controller - 剑道网格

[英]Sending model from view to controller - Kendo grid

I have a method which return a view and a model to the view.我有一个返回视图和 model 到视图的方法。

public async Task<IActionResult> Upload(IFormFile file){

//code shortened for brevity
ViewBag.Message = String.Format(cmdMessage);
return View("Index", three);

}

and I have my view, where I have a Kendo grid, like so:我有我的观点,我有一个剑道网格,就像这样:

@model IEnumerable<ModelLayer.Models.TableNotificationModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Kendo.Mvc
@using Kendo.Mvc.UI
@{ ViewData["Title"] = "UPLOAD"; }

<div class="clearfix">
    @(Html.Kendo().Grid<ModelLayer.Models.TableNotificationModel>()
        .Name("notificationGrid")
        .Pageable(pageable => pageable.Input(true).Numeric(false))
        .Scrollable()
        .Sortable()
        .Filterable()
        .ColumnMenu()

        .Columns(columns =>
        {
            columns.Bound(c => c.OPERATOR_OBJECTID).Title("ID").Hidden();
            columns.Bound(c => c.SETTLEMENT_OBJECTID).Title("settlement code").Width("100px");
            columns.Bound(c => c.TECHNOLOGY_OBJECTID).Title("tech code").Width("100px");
            columns.Bound(c => c.UPLOAD_SPEED_CLASS_OBJECTID).Title("upload").Width("100px");
            columns.Bound(c => c.DOWNLOAD_SPEED_CLASS_OBJECTID).Title("download").Width("100px");
            columns.Bound(c => c.DATA_CATEGORY_QOS_OBJECTID).Title("data category").Width("100px");
            columns.Bound(c => c.SHAPE).Title("shape").Width("100px");
            columns.Bound(c => c.messageOut).Title("message").Width("100px");
        })
        .Excel(excel => excel
        .FileName("Kendo UI Grid Export.xlsx")
        .Filterable(true)
        .ProxyURL(Url.Action("Excel_Export_Save", "Upload")))
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Read(read => read.Action("Upload_Read", "Upload").Data("additionalData"))
            )
    )

</div>

<script>
    function additionalData(e) {
        return {
            additional: "custom Text"
        };
    }
</script>

I have this js function additionalData but I am not sure how to send the model from the function to the method in the controller to this Upload_read method which will populate the Kendo grid with data. I have this js function additionalData but I am not sure how to send the model from the function to the method in the controller to this Upload_read method which will populate the Kendo grid with data.

public ActionResult Upload_Read([DataSourceRequest] DataSourceRequest request)
 {
   DataSourceResult dataSource = result.ToDataSourceResult(request);
   return Json(dataSource.ToDataSourceResult(request));
 }

I am not entirely sure how to send the model.我不完全确定如何发送 model。 Any advice or suggestion?有什么建议或建议吗?

Maybe this will come in handy to someone, here's how I made it word:也许这对某人会派上用场,这就是我所说的:

 function sendAdditional() {
        
        var data = JSON.parse('@Html.Raw(Json.Serialize(Model))');
        console.log("index data", data)

        return {
            model: data
        }
    }

and the controller和 controller

public ActionResult Upload_Read([DataSourceRequest] DataSourceRequest request, List<TableNotificationModel> model)
        {
            return Json(dataSource.ToDataSourceResult(request));
        }

and I am getting the list of models in the controller from the view.我正在从视图中获取 controller 中的模型列表。

Why would you send the data to the server so that you can get it in the table later?为什么要将数据发送到服务器,以便以后可以在表中获取它? If you just need to build a table then use:如果您只需要构建一个表,请使用:

<div class="clearfix">
    @(Html.Kendo().Grid(Model)
        .Name("notificationGrid")
   ...

If the question is in sorting, etc., then you can simply put the parameter ServerOperation(false).如果问题是在排序等方面,那么你可以简单地把参数ServerOperation(false)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kendo MVC Razor Grid如何从控制器传递单个模型而不是集合 - Kendo MVC Razor Grid How to pass a single model rather collection from the controller Kendo Grid MVC-如何在EditorViewData中引用网格视图模型 - Kendo Grid MVC - how reference grid view model in EditorViewData 以表格形式发送剑道网格 - Sending kendo grid in form 发送文件以从控制器查看 - Sending files to view from controller ASP.NET - MVC 从控制器发送和接收模型到视图并返回控制器 - ASP.NET - MVC Sending and receiving model from controller to view and back to controller 从视图中通过控制器和模型发送然后检索文本以查看时出现奇怪的结果 - Weird result when sending and then retrieving text from view through controller and model to view 如何从Kendo分页和过滤的网格中删除所有记录(在控制器中) - How to delete all records from a Kendo paged and filtered grid (in the controller) 从MVC Controller中的Telerik Kendo Grid获取检查的行 - Getting checked rows from Telerik Kendo Grid in MVC Controller 将大型 Model 列表从视图发送到 controller c# mvc Z60C05C632A28229A8737C72E - Sending large Model list from view to controller c# mvc razor Model 未从视图发布到 Controller - Model not posting from View to Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM