I have a Kendo Grid, in which I added a custom button in the toolbar. I have mapped a on click function to that button.
<div class="row">
<div class="clearfix">
@(Html.Kendo().Grid<ModelLayer.Models.TableNotificationModel>()
.Name("successfullData")
.ToolBar(e =>
{
e.Custom().Text("Save").HtmlAttributes(new { id = "customSaveButton", @class = "floatRight" });
})
.Pageable(pageable => pageable.Input(true).Numeric(false))
.Scrollable()
.Sortable()
.Filterable()
.ColumnMenu()
.Groupable()
.Columns(columns =>
{
columns.Bound(c => c.OPERATOR_OBJECTID).Title("ID").Hidden();
columns.Bound(c => c.SETTLEMENT_CODE).Title("settlement code").Width("100px");
columns.Bound(c => c.TECHNOLOGY_CODE).Title("tech code").Width("100px");
columns.Bound(c => c.UPLOAD_SPEED_CLASS_CODE).Title("upload").Width("100px");
columns.Bound(c => c.DOWNLOAD_SPEED_CLASS_CODE).Title("download").Width("100px");
columns.Bound(c => c.DATA_CATEGORY_QOS_CODE).Title("data category").Width("100px");
columns.Bound(c => c.SHAPE).Title("shape").Width("100px");
columns.Bound(c => c.messageOut).Title("message").Width("100px");
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Upload_Read", "Upload").Data("sendAdditional"))
)
)
</div>
</div>
<script>
function sendAdditional() {
var data = JSON.parse('@Html.Raw(Json.Serialize(Model?.TableNotificationModel))');
return {
model: data
}
}
$("#successfullData").on("click", "#customSaveButton", function () {
var model = JSON.parse('@Html.Raw(Json.Serialize(Model?.TableNotificationModel))');
$.ajax({
method: "POST",
url: '@Url.Action("SaveFile", "Upload")',
data: {
model: model,
saveType: saveType
}
})
});
</script>
I added a function which send the model via an ajax call to my controller where I am returning a view. The problem is, the custom save button adds a #
in the URL and I think it's because of that I cannot return the view of my action in the controller.
public ActionResult SaveFile(List<TableNotificationModel> model)
{
//code shortened for brevity
ViewBag.Message = String.Format(cmdMessage);
return View(tModel);
}
I am kind of stuck, I don't know how to proceed. Any suggestions?
Check if your javascript function is identifying your button event by the ID: "customSaveButton".
For example:
$('#customSaveButton').on('click', function () {
$.ajax({
url: '/YourContreoller/SaveFile',
type: 'POST',
dataType: 'json',
data: $('#dataThatYouWantToSend').serialize(),
success: function (sucess) {
console.log("Success");
document.location.href = '/'
},
error: function (xhr, textStatus, errorThrown) {
console.log(textStatus);
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.