Reputation: 318
In Web Application I created a Page:DetailPage
public void OnGet(int id)
{
var bll = new BLL.Articles();
Item = bll.GetModel(id);
if (Item == null)
{
RedirectToPage("Blogs");
}
}
The URL is
localhost/Detail?id=1
Can I make it as the web API URL such as `
localhost/Detail/1
I added [HttpGet("id")]
but is not working as expected.
Upvotes: 1
Views: 509
Reputation: 4634
You can just add this to the top of your *.cshtml
pages:
@page "{id:int}"
Then in your details pages:
public void OnGet([FromRoute] int id)
No need to modify your Startup.cs
file.
Upvotes: 2
Reputation: 2234
As @Nkosi provided the proper document in comments you must modify Startup.cs
Change ConfigureServices
method like this:
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_0)
.AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/Detail", "Detail/{id}");
});
Now implement your standard view
@page
@model Item
<p>@Model.[property]</p>
Upvotes: 1