Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Clear cart returns html instead of json #258 (#272)

Krzysztof Pajakba36c0013a3e
diff --git a/src/Web/Grand.Web/Controllers/BasePublicController.cs b/src/Web/Grand.Web/Controllers/BasePublicController.cs
index 07eba20ed..cfee5c8ef 100644
--- a/src/Web/Grand.Web/Controllers/BasePublicController.cs
+++ b/src/Web/Grand.Web/Controllers/BasePublicController.cs
@@ -41,5 +41,13 @@ namespace Grand.Web.Controllers
return base.View(viewName, model);
}
+
+ public override RedirectToRouteResult RedirectToRoute(string routeName)
+ {
+ if (IsJsonResponseView())
+ return RedirectToRoute("Route", new { routeName = routeName });
+
+ return base.RedirectToRoute(routeName);
+ }
}
}
diff --git a/src/Web/Grand.Web/Controllers/CommonController.cs b/src/Web/Grand.Web/Controllers/CommonController.cs
index 921186ebe..45befed69 100644
--- a/src/Web/Grand.Web/Controllers/CommonController.cs
+++ b/src/Web/Grand.Web/Controllers/CommonController.cs
@@ -127,6 +127,16 @@ namespace Grand.Web.Controllers
return View();
}
+ public virtual IActionResult Route(string routeName)
+ {
+ if (string.IsNullOrEmpty(routeName))
+ return Json(new { redirectToUrl = string.Empty });
+
+ var url = Url.RouteUrl(routeName);
+
+ return Json(new { redirectToUrl = url });
+ }
+
//external authentication error
public virtual IActionResult ExternalAuthenticationError(IEnumerable<string> errors)
{
diff --git a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs b/src/Web/Grand.Web/Endpoints/EndpointProvider.cs
index 34065f149..d68b240e6 100644
--- a/src/Web/Grand.Web/Endpoints/EndpointProvider.cs
+++ b/src/Web/Grand.Web/Endpoints/EndpointProvider.cs
@@ -404,6 +404,11 @@ namespace Grand.Web.Endpoints
pattern + "access-denied",
new { controller = "Common", action = "AccessDenied" });
+ //page not found
+ endpointRouteBuilder.MapControllerRoute("Route",
+ "route",
+ new { controller = "Common", action = "Route" });
+
//lets encrypt
endpointRouteBuilder.MapControllerRoute("well-known",
".well-known/pki-validation/{fileName}",