Json and Controller

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi,

I need to create a Jsonresult method in Catalog Controller..

How can I made it?

I have a js file.

        $.post('/Catalog/GetProductsMoreOneTest/' + page, function (data) {
            if (data != '') {
                $('.product-grid').append(data);
            }
            else {
                page = -1;
            }
            _inCallback = false;
            $('.DivWait').empty();
        }, "json");


In Nop.Web\Controllers\CatalogController.cs I have:

[HttpPost]
        public JsonResult GetProductsMoreOneTest(int page)
        {
            var category = _categoryService.GetCategoryById(4); //test only

            var model = category.ToModel();

            //products
            var products = _productService.SearchProducts(category.Id, 0,
                _catalogSettings.IncludeFeaturedProductsInNormalLists ? null : (bool?)false,
                null, null,
                0, string.Empty, false, _workContext.WorkingLanguage.Id, null,
                (ProductSortingEnum)5, page, 4); // test only

            var viewMode = _catalogSettings.DefaultViewMode;

            model.Products = products.Select(x => PrepareProductOverviewModel(x)).ToList();

            model.PagingFilteringContext.LoadPagedList(products);
            model.PagingFilteringContext.ViewMode = viewMode;

            return Json(model, JsonRequestBehavior.AllowGet);
        }


But not works... the method not is raised..

What I missing?
Can I call a json method just doing what I did?

Thanks
12 years ago
Found out..
just mapped the controller again...

There's a new method called Idnex in controller

router file:

            routes.MapLocalizedRoute("CategoryN",
                            "{controller}/{action}/{page}",
                            new { controller = "Catalog", action = "Idnex", id = UrlParameter.Optional });


Controller file:

        public ActionResult Idnex() //<-- wrong name on purpose
        {
            return View();
        }


that is all.. now my json method is invoked...

Thanks..
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.