Routing in MVC Core 2.0.0 with Tag helper

176 views Asked by At

Mvc Core 2 has a bug that we cannot use page keyword so i changed it to pageid now that bug is fixed but I have a new bug

routes.MapRoute(
                name: null,
                template: "Community/Page{pageID}",
                defaults: new { Controller = "Forum", action = "Home" });
            routes.MapRoute(
                name: "default",
                template: "{controller=Forum}/{action=Home}/{id?}");
            routes.MapRoute(
                name: null,
                template: "",
                defaults: new { controller = "Forum", action = "Home", pageID = 1 });
            routes.MapRoute(name: null, template: "{controller}/{action}/{id?}");

and my tag helper

[HtmlAttributeName(DictionaryAttributePrefix = "page-url-")]
  public Dictionary<string, object> pageUrlValues { set; get; }
  public override void Process(TagHelperContext context, TagHelperOutput output)
  {
    pageUrlValues["page"] = i;

I should get

url/Community/Page5

but what i get is

url/Community/Page1?page=5

this works fine but makes my mapping useless and if i changed page in tag helper to pageID the page's id now updated as expected to page5 / page4 etc but the content of these pages doesn't update only the content of page1 get displayed

2

There are 2 answers

0
AudioBubble On

it turns out that i forgot to update the controller's parameter page to pageid

4
Hung Quach On

Try to change {pageID} to {page}

routes.MapRoute(
                name: null,
                template: "Community/Page{page}",
                defaults: new { Controller = "Forum", action = "Home" });
            routes.MapRoute(
                name: "default",
                template: "{controller=Forum}/{action=Home}/{id?}");
            routes.MapRoute(
                name: null,
                template: "",
                defaults: new { controller = "Forum", action = "Home", pageID = 1 });
            routes.MapRoute(name: null, template: "{controller}/{action}/{id?}");