0

Syncfusion Datagrid を使用する MVC4 アプリケーションがあります。ビューには、jquery 関数を実行するボタン (xfrButton) があります。

            $(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 への呼び出しは魅力的に機能し、返されるデータは、起動する次のビューのデータを含むビューモデルです。唯一の問題は、次のビュー/アクション (この場合は targetURL の URL) を起動するために何をしようとしても、現在のビューとデータグリッドがブラウザーに残っていることです。

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");}) 
%>
4

1 に答える 1

0
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`
        }
于 2013-08-08T09:57:30.623 に答える