简体   繁体   中英

How to route to "www.example.com/sample-article-name" to RazorPage Index.cshtmll with articleName=sample-article-name [MVC Core2.2]

How to access article by url: www.example.com/some-article-name in Razor pages ?

I create a blog portal in Asp.Net MVC Core 2.2 RazorPage.

I have a Page Index.chhtml with the method public void OnGet(string id) I can access the Index with int parameter like that: www.example.com/234 - this work's

But putting string : www.example.com/some-string - doesn't work - HTTP ERROR 404

I would like access article by url: www.example.com/some-article-name.

Instead of id parameter at OnGet method, add page parameter at the top of index.cshtml

@page "{menuUrl?}"

and detect its value at OnGet by using RouteData.Values["menuUrl"]?.ToString()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM