Search code examples
c#ajaxmodel-view-controllerasp.net-mvc-5asp.net-mvc-views

MVC 5 Cannot get another view to load


I cannot get another view to load after initial load of my MVC project. I am using an ajax call to run a method called SlideLayoutView within a controller called SlideView.

Here is the ajax call:

     $.ajax({
                url: "/SlideView/SlideLayoutView",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(id),
                success: function (result) {

                },
            });

Here is the route for it:

        //slide layout view
        routes.MapRoute("SlideViewPage",//Route name
                        "SlideView/SlideLayoutView/{id}",//URL
                        new { controller = "SlideView", action = "SlideLayoutView", id = UrlParameter.Optional },// paramter defaults
                        new[] { "ChootaAuthor.web.Controllers" });

And here is the method within the SlideViewController:

        public ActionResult SlideLayoutView(int id = 0)
    {
        ViewBag.Message = "Slide View Page";

        var model = new SlideViewModel();

        model.slideID = 1;
        model.slideTitle = "test";

        return View("SlideLayoutView", model);
    }

If I run the view itself it works fine. If I navigate to it with /SlideView/SlideLayoutView/-1 it works fine. But shouldn't it work as well if I return the View? Please help


Solution

  • You aren't doing anything with the AJAX result after calling the view.

     success: function (result) {
    NOTHING HAPPENS HERE, SO YOU CANT EXPECT ANYTHING TO HAPPEN
                    },