【发布时间】:2021-12-05 05:17:36
【问题描述】:
我正在尝试使用 Ajax 查询将查询发送到控制器,但我做不到。我知道的不多,我是实习生。在做之前,我看了一下如何用ajax查询发送数据,但是没有用。如果您能帮助我,我将不胜感激。
我的 .aspx 代码:
<script type="text/javascript">
function customActionOn(itemStockCode) {
$.ajax({
url: '/SAPManagement/SAPUpdate.aspx/CustomActionOn',
dataType: 'json',
type: 'POST',
data: "{'itemStockCode': '"+itemStockCode+"'}",
contentType: 'application/json; charset=utf-8'
});
}
function customActionOff(itemStockCode) {
$.ajax({
url: '/SAPManagement/SAPUpdate.aspx/CustomActionOff',
dataType: 'json',
type: 'POST',
data: "{'itemStockCode': '" + itemStockCode + "'}",
contentType: 'application/json; charset=utf-8'
});
}
</script>
<telerik:GridTemplateColumn UniqueName="GetDeatils" ShowFilterIcon="false" AllowFiltering="false" HeaderText="Open and Close The Product On The Web" FilterControlWidth="10px" AutoPostBackOnFilter="false">
<ItemTemplate>
<%--<asp:Button CommandName="GetDeatils" ID="GetDeatils2" OnClientClick='<%# "javascript:openwin("+Eval("ItemStockCode").ToString()+")" %>'
runat="server" Text="Detay"></asp:Button>--%>
<asp:Button ID="Button3" runat="server" CssClass="btn btn-block green" Text="Open" OnClientClick='<%# "customActionOn("+Eval("ItemStockCode").ToString()+")" %>'></asp:Button>
<asp:Button ID="Button1" runat="server" CssClass="btn btn-block red" Text="Close" OnClientClick='<%# "customActionOff("+Eval("ItemStockCode").ToString()+")" %>'></asp:Button>
</ItemTemplate>
</telerik:GridTemplateColumn>
.aspx.cs 代码:
[System.Web.Services.WebMethod]
public void CustomActionOn(string itemStockCode)
{
products = new LogicRules.B2B.BL_Product().GetAllProductsForSAPUpdate().OrderBy(x => x.ItemName).ToList();
var selectedProduct = products.Where(x => x.ItemStockCode == itemStockCode).FirstOrDefault();
selectedProduct.PublishOnB2B = true;
new Core.Log.ArkLogs().WriteProductUpdateLog(JsonConvert.SerializeObject(selectedProduct), User.Identity.GetUserId<int>(), "Product", "ISBN", selectedProduct.ItemStockCode);
var retValues = new SapFunction.ProductFunction().updateProduct(selectedProduct);
}
[System.Web.Services.WebMethod]
public void CustomActionOff(string itemStockCode)
{
products = new LogicRules.B2B.BL_Product().GetAllProductsForSAPUpdate().OrderBy(x => x.ItemName).ToList();
var selectedProduct = products.Where(x => x.ItemStockCode == itemStockCode).FirstOrDefault();
selectedProduct.PublishOnB2B = false;
new Core.Log.ArkLogs().WriteProductUpdateLog(JsonConvert.SerializeObject(selectedProduct), User.Identity.GetUserId<int>(), "Product", "ISBN", selectedProduct.ItemStockCode);
var retValues = new SapFunction.ProductFunction().updateProduct(selectedProduct);
}
我无法通过这种方式向控制器发送数据。我得到了正确的 itemstockcode 值。但数据不会进入控件。如果您能帮助我,我将不胜感激。
【问题讨论】:
标签: asp.net ajax telerik asp.net-ajax