1

Clicking a certain Ajax ActionLink in this app I just inherited produces a POST request AND a GET request (POST and then a GET immediately after). The first request hits the HttpPost method on the server, but the second request (the GET) throws a "404 (Not Found)" error in the browser. How do I stop the unwanted GET request? Where is it coming from?

If I change the method from POST to GET, the reverse occurs with the POST throwing the error instead of the GET.

I searched the application for similar requests to the same HttpPost method that were configured as GETs and there are none.

I searched for custom JavaScript that was attaching an extra click event to all links and there were no instances of that. Could there be other events that would produce the same result in this instance?

Chrome DevTools Screenshot

In DocumentManagementController.cs:

[HttpPost]
public ActionResult OpenPopup(string ntgLoadId) { ... }

In _GridLoadsAddendum.cshtml:

@Html.DevExpress().GridView(
settings =>
{
    settings.Name = "DetailedGrid_" + Model.LoadId;
    settings.Width = Unit.Percentage(100);
    settings.Settings.ShowFilterRow = false;
    settings.Settings.ShowGroupPanel = false;
    settings.Settings.ShowFooter = false;
    settings.Settings.ShowColumnHeaders = false;
    settings.KeyFieldName = "NtgLoadId";

    settings.Columns.Add(column =>
    {
        column.FieldName = "Status";
        column.Caption = "Status";
        column.Width = Unit.Pixel(83);
        column.SetDataItemTemplateContent(c =>
        {
            ViewContext.Writer.Write(
                Ajax.ActionLink(
                    DataBinder.Eval(c.DataItem, "Status").ToString(),
                    "OpenPopup",
                    "DocumentManagement",
                    new
                    {
                        ntgLoadId = c.KeyValue.ToString()
                    },
                    new AjaxOptions
                    {
                        HttpMethod = "POST",
                        InsertionMode = InsertionMode.Replace,
                        UpdateTargetId = "ModalContainer",
                        AllowCache = false
                    },
                    new
                    {
                        @class = "status-link",
                        data_Toggle = "modal",
                        data_Target = "#ModalContainer",
                        data_backdrop = "static",
                        data_Keyboard = "false"
                    }).ToHtmlString());
        });
    });

    settings.Styles.Table.CssClass = "MVCxGridViewTable";
    settings.Styles.Header.CssClass = "MVCxGridViewHeader";
    settings.Styles.Cell.CssClass = "MVCxGridViewCell addendum";
    settings.Styles.CommandColumnItem.CssClass = "MVCxGridViewCell";
    settings.Styles.AlternatingRow.CssClass = "MVCxGridViewAlternatingRow addendum";
    settings.Styles.PagerBottomPanel.CssClass = "MVCxGridViewPagerBottomPanel";
    settings.Settings.ShowFooter = false;
    settings.ClientSideEvents.BeginCallback = "initechPortal.carrierPaymentStatusHelper.gridResultsHelper.beginCallback";
    settings.CallbackRouteValues = new
    {
        Controller = "CarrierPaymentController",
        Action = "GridLoadsAddendum",
        Id = Model.LoadId
    };
    settings.DataBound = (sender, e) =>
    {
        MVCxGridView gv = sender as MVCxGridView;
        gv.Visible = gv.VisibleRowCount > 0;
    };
}).BindToLINQ(
    string.Empty,
    string.Empty,
    new EventHandler<DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs>(
    (s, e) =>
    {
        e.QueryableSource = Model.CarrierPaymentResultData;
        e.KeyExpression = "ntgLoadId";
    })).GetHtml();
CJ314
  • 11
  • 1
  • 1
  • 1
    Are you using `jquery.unobtrusive-ajax.js` or `jquery.unobtrusive-ajax.min.js` script file inside view? Not adding the file may cause the AJAX link uses HTTP GET instead of POST, which throwing 404. – Tetsuya Yamamoto Dec 10 '18 at 02:12

0 Answers0