asp.net-mvc-routing

Redirecting to a custom route in MVC

怎甘沉沦 提交于 2021-02-11 08:06:42
问题 I have setup a custom route in my MVC site. I am having trouble figuring out how to redirect to it though. Here is my custom route code: public class MemberUrlConstraint : IRouteConstraint { public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { if (values[parameterName] != null) { var permalink = values[parameterName].ToString(); return string.Equals(permalink, Member.GetAuthenticatedMembersUrl(),

Asp.net MVC 5 MapRoute for multiple routes

爱⌒轻易说出口 提交于 2021-02-09 10:56:38
问题 I have 3 routes in RouteConfig: routes.MapRoute( name: "ByGroupName", url: "catalog/{categoryname}/{groupname}", defaults: new { controller = "Catalog", action = "Catalog" } ); routes.MapRoute( name: "ByCatName", url: "catalog/{categoryname}", defaults: new { controller = "Catalog", action = "Catalog" } ); routes.MapRoute( name: "ByBrandId", url: "catalog/brand/{brandId}", defaults: new { controller = "Catalog", action = "Catalog" } ); and this is my action controller receiving parameters:

How to use RenderAction with custom Routing?

百般思念 提交于 2021-02-08 11:16:25
问题 we are starting to use routes for our MVC project, so we basicly replace ActionLink() with RouteLink() - now we want to replace RenderAction() to add route information we need (mainly the routename)... Here is one of our mappings: // Route für Tools route = routes.MapRoute( name: "Tool", url: "tool/{controller}/{action}", defaults: new { controller = "Home", action = "Index" }, namespaces: new[] { "Web.Controllers.Tool" }); route.DataTokens["UseNamespaceFallback"] = false; So with

How to use RenderAction with custom Routing?

不问归期 提交于 2021-02-08 11:14:13
问题 we are starting to use routes for our MVC project, so we basicly replace ActionLink() with RouteLink() - now we want to replace RenderAction() to add route information we need (mainly the routename)... Here is one of our mappings: // Route für Tools route = routes.MapRoute( name: "Tool", url: "tool/{controller}/{action}", defaults: new { controller = "Home", action = "Index" }, namespaces: new[] { "Web.Controllers.Tool" }); route.DataTokens["UseNamespaceFallback"] = false; So with

MVC Custom Routing only for GET requests

强颜欢笑 提交于 2021-02-08 10:13:12
问题 I have a custom routing class which I added to the RouteConfig public static class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.Add(new CustomRouting()); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } The CustomRouting class looks like this: public class CustomRouting : RouteBase { public override

MVC 5 Routing with parameter using @Url.RouteUrl

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 10:45:51
问题 I have an ActionResult that I have applied a routing attribute to: [Route("myproduct/{productID}", Name = "myproduct")] [MvcSiteMapNode(Title = "Products", ParentKey = "products", Key = "myproducts")] public ActionResult myproducts(int productID) ... I am trying to link to the view via a RouteUrl: <a href="@Url.RouteUrl("myproducts", @Model.myproducts[i].productID)">Buy</a> The resulting html does not even include a href: <a>Buy</a> If I remove the parameter it works: [Route("myproducts",

ASP.Net MVC RouteAttribute Error with Route Parameter

﹥>﹥吖頭↗ 提交于 2021-01-28 07:44:23
问题 I'm getting a lot of different errors while trying to add Route mapping to a certain action! I'm trying to get this route for GET /Admin/Users/User/1 and POST /Admin/Users/User But sadly there is already a User property in Controller! So i cannot use public ActionResult User(long id) because i need to hide the user property (that i need to keep because it's the IPrincipal of the Controller and i still get the same error). Defining route this way : // First in RouteConfig routes

How do you link to an action that takes an array as a parameter (RedirectToAction and/or ActionLink)?

爷,独闯天下 提交于 2021-01-02 08:11:14
问题 I have an action defined like so: public ActionResult Foo(int[] bar) { ... } Url's like this will work as expected: .../Controller/Foo?bar=1&bar=3&bar=5 I have another action that does some work and then redirects to the Foo action above for some computed values of bar . Is there a simple way of specifying the route values with RedirectToAction or ActionLink so that the url's get generated like the above example? These don't seem to work: return RedirectToAction("Foo", new { bar = new[] { 1,