What can be used to get the URL of the page which is in this path of the project <website>/Pages/Account/Logout.cshtml
This is using view model razor pages and not mvc controller/action
When I use Url.Action("/Account/Logout", new { logoutId = ogoutId });
it says cannot resolve action /Account/Logout
Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
Action(String, String, Object, String)Generates a fully qualified URL to an action method by using the specified action name, controller name, route values, and protocol to use.
Action method only creates the url not the complete hyperlink, to create hyperlink we need to use Html. ActionLink covered next. To access these querystring values in the action method, we can use Request.QueryString like below. CONTROLLER ACTION METHOD public ActionResult Index() { string com = Request.
You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder. Razor Pages use the folder structure as a convention for routing requests.
In Razor Pages, you could use @Url.Page.
<a href="@Url.Page("/Account/Logout",new { logoutId = 1 })">Logout</a>
Or use asp-page
directly,see more usage here.
<a asp-page="/Account/Logout" asp-route-logoutId ="1">Logout</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With