gpt4 book ai didi

javascript - 如何将值从 MVC 中的 Javascript 代码传递给 Controller

转载 作者:行者123 更新时间:2023-12-04 05:19:05 28 4
gpt4 key购买 nike

其实我有这样的场景:

我正在通过 Javascript 获取 GridView 中已检查记录的值。
现在我需要将这些值发送到 Controller 以删除这些记录。

<script type="text/javascript">
$(function OnDelete() {
$('#btn_Delete').click(function ()
{
gvPaging.PerformCallback();
});
});

function OnBeginCallback(s, e) {
var selectedValues = s.GetSelectedKeysOnPage();
e.customArgs["ID"] = "";
for (var i = 0; i < selectedValues.length; i++) {
e.customArgs["ID"] += selectedValues[i] + ',';
}
}
</script>

我的 GridView 是这样的:
<% 
Html.DevExpress().GridView(
settings =>
{
settings.Name = "gvPaging";
settings.CallbackRouteValues = new { Controller = "GridView", Action = "PagingPartial" };
settings.Width = Unit.Percentage(100);
settings.KeyFieldName = "ID";

settings.CommandColumn.ShowSelectCheckbox = true;
settings.CommandColumn.SetHeaderTemplateContent(c =>
{
Html.DevExpress().CheckBox(settingsCheckBox =>
{
settingsCheckBox.Name = "cbSelectAll";
settingsCheckBox.Name = "Select All";
settingsCheckBox.Properties.ValueType = typeof(bool);

settingsCheckBox.Properties.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ if(s.GetChecked()) {0}.SelectRows(); else {0}.UnselectRows(); }}", settings.Name);
settingsCheckBox.Checked = c.Grid.VisibleRowCount == c.Grid.Selection.Count;
}).Render();
});
settings.SettingsBehavior.AllowSelectByRowClick = true;
//settings.Columns.Add("ID");
settings.Columns.Add("Name");
settings.Columns.Add("EmailID");
settings.Columns.Add("MobileNumber");
settings.Columns.Add("Address");
settings.SettingsPager.Position = PagerPosition.Bottom;
settings.SettingsPager.FirstPageButton.Visible = true;
settings.SettingsPager.LastPageButton.Visible = true;
settings.SettingsPager.PageSizeItemSettings.Visible = true;
settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };


settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "GridView", Action = "InlineEditingAddNewPartial" };
settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "GridView", Action = "InlineEditingUpdatePartial" };
//settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "GridView", Action = "InlineEditingDeletePartial" };
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
//settings.SettingsBehavior.ConfirmDelete = true;

settings.Settings.ShowFilterRow = true;
settings.Settings.ShowFilterRowMenu = true;
settings.CommandColumn.Visible = true;
settings.CommandColumn.ClearFilterButton.Visible = true;
settings.CommandColumn.NewButton.Visible = true;
//settings.CommandColumn.DeleteButton.Visible = true;
settings.CommandColumn.EditButton.Visible = true;
settings.Settings.VerticalScrollBarMode = ScrollBarMode.Visible;
//settings.ClientSideEvents.SelectionChanged = "SelectionChanged";
settings.ClientSideEvents.BeginCallback = "OnBeginCallback";

})
.Bind(Model)
.Render();

%>

最佳答案

您可以在脚本中使用 AJAX。

像这样的东西

$.ajax({
url: 'Your method in controller which will delete the records',
type: 'POST',
data: ' data which you want to send to controler ',
});

关于javascript - 如何将值从 MVC 中的 Javascript 代码传递给 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13878418/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com