JQuery函数成功未使用Syncfusion Datagrid启动新视图
我有一个使用Syncfusion数据网格的MVC4应用程序。在视图中,我有一个执行jquery函数的按钮xfrButton:JQuery函数成功未使用Syncfusion Datagrid启动新视图,jquery,asp.net-mvc-4,syncfusion,Jquery,Asp.net Mvc 4,Syncfusion,我有一个使用Syncfusion数据网格的MVC4应用程序。在视图中,我有一个执行jquery函数的按钮xfrButton: $(document).ready(function () { // Handle the clicking of the Request Transfer button $('#xfrButton').click(function () { // Initiali
$(document).ready(function () {
// Handle the clicking of the Request Transfer button
$('#xfrButton').click(function () {
// Initialize object to hold data grid
var GridObj = $find("AssetGrid")
// Initialize object to hold the filters the user selected in the grid
var gridData = Sys.Serialization.JavaScriptSerializer.serialize(GridObj._filters);
// Call controller action to process selected filters passing the filters variable (gridData)
$.post('<%: ResolveUrl("~/Step05_AssetsValidBUActiveCRS/RequestToTransfer/")%>', { select: gridData },
function (data) {
// If successful, call the Transfer Request View
var targetModel = Sys.Serialization.JavaScriptSerializer.serialize(data);
var targetURL = '~/Step05_TransferRequest/Index/?transferVM=' + targetModel.toString();
// var targetURL = '~/Step05_TransferRequest/Index/';
//TODO: Figure out a way to launch a new view upon success return from above statement
// Must pass the data returned from the above .post to the new controller action
// Current process just stays on the existing screen. Neither of the following work:
$(this).load(targetModel);
// window.location.href(targetURL);
}
, "json")
})
})
在.post中调用/Step05_AssetsValidBUActiveCRS/RequestToTransfer就像一个符咒,返回的数据是一个viewmodel,其中包含我要启动的下一个视图的数据。唯一的问题是,无论我如何尝试启动下一个视图/操作(在本例中为targetURL中的URL),当前视图和datagrid在浏览器中都保持不变
我可以再次单击xfrButton按钮,它会触发上面的例程,该例程会再次执行.post操作,但仍然不会触发targetURL值。为什么jquery不启动新视图
以下是视图中的Syncfusion代码以及按钮,以供参考:
<p>
<input id="xfrButton" type="submit" value="Request Transfer To" />
</p>
<%=Html.Syncfusion().Grid<AMSUtilityMVC4.ViewModels.Step05ListAssetsValidBUActiveCRSViewModel>("AssetGrid")
.Datasource(Model)
.EnableFiltering() /*Filtering Enabled*/
.EnableSorting() /*Sorting Enabled*/
.EnablePaging() /*Paging Enabled*/
.AllowResizing(true)
.Scrolling(scroll => scroll.Height(300).Width(1050))
.EnableScrolling()
.AllowSelection(true).RowsSelectionMode(RowsSelectionMode.Toggle)
.Column(cols =>
{
cols.Add(c => c.REMS).HeaderText("REMS").Width(75);
cols.Add(c => c.companyName).HeaderText("Company").Width(150);
cols.Add(c => c.LVID).HeaderText("LVID").Width(75);
cols.Add(c => c.entity).HeaderText("BU").Width(75);
cols.Add(c => c.locationDescription).HeaderText("Location Description").Width(150);
cols.Add(c => c.assetNumber).HeaderText("Asset No").Width(100);
cols.Add(c => c.majorCategory).HeaderText("Major Cat").Width(150);
cols.Add(c => c.minorCategory).HeaderText("Minor Cat").Width(150);
cols.Add(c => c.FACode).HeaderText("FA Code").Width(75);
cols.Add(c => c.description).HeaderText("Title").Width(150);
cols.Add(c => c.cost).HeaderText("Cost").TextAlign(Syncfusion.Mvc.Grid.TextAlignment.Right).Format("{0:C}").Width(70);
cols.Add(c => c.nbv).HeaderText("NBV").Width(60);
cols.Add(c => c.GOC).HeaderText("GOC").Width(75);
cols.Add(c => c.FEIN).HeaderText("FEIN").Width(75);
cols.Add(c => c.datePlacedInService).HeaderText("In Service").Width(150);
cols.Add(c => c.vendorName).HeaderText("Vendor Name").Width(150);
cols.Add(c => c.accountingKey).HeaderText("Acct Key").Width(150);
cols.Add(c => c.locationKey).HeaderText("Location Key").Width(150);
cols.Add(c => c.state).HeaderText("State");
})
.ClientSideEvents(e => e.OnToolbarClickEvent("OnToolbarClickEvent"))
.ToolBar(tools =>
{
// Adding the custom toolbar items.
// Add(customItemtitle, customItemcaption, customItemCssClass)
tools.Add(GridToolBarItems.ExcelExport, "Excel Export")
.Add(GridToolBarItems.PDFExport, "PDF Export")
.Add(GridToolBarItems.Custom, "Transfer Request To", "RequestTransfer");
})
.Mappers(map =>{map.ExportExcelAction("GridExportToExcel")
.ExportPdfAction("GridExportToPDF");})
%>
请尝试使用$correctselector.loadtargetURL,而不要使用$this.loadtargetModel。如果是整页,请使用$document.documentElement作为选择器或存储库,以更正我在问题中犯的愚蠢错误。如何使用.load语句将序列化的模型数据传递给控制器?
Your requirement can be solved by passing targetURL in load function. Please refer to the following code snippets:
[JavaScript]
function OnToolbarClickEvent(sender, args) {
var GridObj = sender;
if (args._currentItem.title == "RequestToTransfer") {
$.ajax({
url: "/Home/RequestToTransfer",
data:
{
"select": Sys.Serialization.JavaScriptSerializer.serialize(GridObj._filters)
},
dataType: 'json',
success: function (data) {
var targetModel = Sys.Serialization.`JavaScriptSerializer`.serialize(data);
var targetURL = '/Home/RequestToTransfer/?select=' + targetModel.toString();
// var targetURL = '~/Step05_TransferRequest/Index/';
//TODO: Figure out a way to launch a new view upon success return from above statement
// Must pass the data returned from the above .post to the new controller action
// Current process just stays on the existing screen. Neither of the following work:
$(this).load(targetURL); // pass target URl to load
}
});
}
}
[Controller]
public ActionResult RequestToTransfer(string select)
{
var data = OrderRepository.GetAllRecords();`enter code here`
ViewData["data"] = data.Take(10).ToList();
return Json(data, JsonRequestBehavior.AllowGet); // returns data in success`enter code here`enter code here`
}