Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url.Action alternate in razor page view model class

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

like image 328
Umair Avatar asked Dec 11 '18 22:12

Umair


People also ask

What is the difference between using URL action and HTML ActionLink in a view?

Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.

What is the use of URL action in MVC?

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.

What is action method in URL?

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.

Can you mix razor pages and MVC?

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.


1 Answers

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>
like image 154
Ryan Avatar answered Oct 28 '22 10:10

Ryan