-1

I am sending an ajax call on on a button click to load a partial view in Kendo Modal window. In dev mode it is doing everything fine as expected but giving me a 404 error in live.

Following is my Ajax call

        $('.add_page').click(function (e) {
        e.preventDefault();
        $.ajax({
            url: '../Page/AddEditPage',
            type: 'Get',
            accepts: 'text/html',
            context: self,
            success: self.addEditPageWindowCallBack,
            error: function () { toastr.error('Error: Something went wrong'); },
            complete: function () { }
        });
    });

Following is the Ajax success method

    addEditPageWindowCallBack: function (html, textStatus, jqXHR) {
    var model = $('#AddEditPageModelWindow').data('kendoWindow');

    if (model === undefined) {
        model = $('#AddEditPageModelWindowLayout').data('kendoWindow');
    }

    model.content(html);
    model.center();
    model.open();
},

My Controller action method is as follow

    public ActionResult AddEditPage(int Id = 0)
    {
        var pageId = Id;
        var pageViewModel = new PageViewModel();

        if(pageId == 0)
        {
            pageViewModel = new PageViewModel
            {
                Page = new Page(),
            };

            pageViewModel.Page.CreatedBy = User.Identity.GetUserId();
        }
        else
        {
            var pageData = pageService.GetPageByPageId(pageId);

            pageViewModel = new PageViewModel
            {
                Page = pageData,
            };
        }

        return PartialView("~/Views/Shared/Page/_AddEditPage.cshtml", pageViewModel);
    }

Initially, I was returning partial view as follow

return PartialView("Page/_AddEditPage", pageViewModel);

That i have changed with the following but still no effect

return PartialView("~/Views/Shared/Page/_AddEditPage.cshtml", pageViewModel);

I am trying to find a resolution to this problem. Any idea either of resolving this issue or if there is any way of catching the exact error in live environment will really help.

Following is the Network screen shot of error

enter image description here

Learning Curve
  • 1,449
  • 7
  • 30
  • 60
  • 1
    Your getting a `404 NotFound`. Always use `Url.Action()` to generate your urls. - `url: '@Url.Action("AddEditPage", "Page")',` –  Feb 27 '18 at 21:41

2 Answers2

1

It seems that the error is probably in following line

 url: '../Page/AddEditPage',

try it with url: '~/../Page/AddEditPage',

MCoder
  • 113
  • 5
1

you can use html helper in your javascript code like

url: '@Html.UrlAction("actionname","controllername")'
Batuhan Kara
  • 263
  • 3
  • 11