[英]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.