Generate dynamic route path in asp.net core

TrinTrin

I have created one .net core application that has below path for crud operations.

Create: http://localhost:1001/admin/123/app/456/user/Create

Update: http://localhost:1001/admin/123/app/456/user/Update

Select: http://localhost:1001/admin/123/app/456/user/Select

Writing below will solve the issue in the URL.

routes.MapRoute("CreateUser", "apps/{appId}/user/create",
  defaults: new { controller = "User", action = "Create" }); 

How to include the same in .cshtml file i.e <a asp-action="Create" asp-controller="User"> Create User </a>

The quick help appreciated.

thirdDeveloper

You can use asp-route-{value} option to indicate route values in anchor tag helper:

<a asp-action="Create" asp-controller="User" asp-route-adminID="@Model.AdminId" asp-route-appId="@Model.AppId"> Create User </a>

Please consider that I assumed that adminId and appId values are provided in the Model of the page. If it's wrong, set appropriate variable instead of those in your code.

For more information, you can check the Microsoft documentation: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper?view=aspnetcore-3.0#asp-route-value

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Path to LocalAppData in ASP.Net Core application

分類Dev

ASP.NET Core CreatedAtRoute No route matches the supplied values

分類Dev

ASP.NET Core 2.0: Authenticate a route without a controller

分類Dev

Route with FromBody doesn't work with ASP.NET Core

分類Dev

Path based authentication in ASP.NET Core MVC 2.0

分類Dev

Remove route from RouteCollection in Asp.Net Core and add new with same route name (nopCommerce-4.00)

分類Dev

.Net Core Dynamic dbContext

分類Dev

ASP.NET Core MVC Mixed Route/FromBody Model Binding & Validation

分類Dev

Asp.Net Core 2.0 error while scaffolding my database to generate Models

分類Dev

.NET CoreとASP.NET Core

分類Dev

.Net Core Override Controller Route for Generic Controller

分類Dev

ASP.NET MVC route to different address

分類Dev

ASP.NET MVC route to different address

分類Dev

ASP.NET Core ToHtmlString

分類Dev

Cookieless ASP.NET Core

分類Dev

How to generate css by database in asp.net..?

分類Dev

ASP.NET CORE MVCルート:asp-all-route-dataで辞書を渡そうとしています

分類Dev

ASP.NET CoreのHttpRequest.PathとHttpRequest.PathBaseの違いは何ですか?

分類Dev

Dynamic User Group Authorization in .NET Core

分類Dev

Changing Request Path in .Net Core 3.1

分類Dev

asp.net dynamic variable in hyperlink

分類Dev

Why do .NET Core and .NET 5 generate an executable?

分類Dev

Path of home directory in asp.net

分類Dev

How to map URL path to physical path in asp.net website

分類Dev

asp.net MVC saving relative path in database as not the full path

分類Dev

ASP.NET Core 3.1ルーティング(Route、ActionName)のローカリゼーションを行う方法は?

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.Net Core SAML authentication

分類Dev

ASP.Net Core SAML authentication

Related 関連記事

  1. 1

    Path to LocalAppData in ASP.Net Core application

  2. 2

    ASP.NET Core CreatedAtRoute No route matches the supplied values

  3. 3

    ASP.NET Core 2.0: Authenticate a route without a controller

  4. 4

    Route with FromBody doesn't work with ASP.NET Core

  5. 5

    Path based authentication in ASP.NET Core MVC 2.0

  6. 6

    Remove route from RouteCollection in Asp.Net Core and add new with same route name (nopCommerce-4.00)

  7. 7

    .Net Core Dynamic dbContext

  8. 8

    ASP.NET Core MVC Mixed Route/FromBody Model Binding & Validation

  9. 9

    Asp.Net Core 2.0 error while scaffolding my database to generate Models

  10. 10

    .NET CoreとASP.NET Core

  11. 11

    .Net Core Override Controller Route for Generic Controller

  12. 12

    ASP.NET MVC route to different address

  13. 13

    ASP.NET MVC route to different address

  14. 14

    ASP.NET Core ToHtmlString

  15. 15

    Cookieless ASP.NET Core

  16. 16

    How to generate css by database in asp.net..?

  17. 17

    ASP.NET CORE MVCルート:asp-all-route-dataで辞書を渡そうとしています

  18. 18

    ASP.NET CoreのHttpRequest.PathとHttpRequest.PathBaseの違いは何ですか?

  19. 19

    Dynamic User Group Authorization in .NET Core

  20. 20

    Changing Request Path in .Net Core 3.1

  21. 21

    asp.net dynamic variable in hyperlink

  22. 22

    Why do .NET Core and .NET 5 generate an executable?

  23. 23

    Path of home directory in asp.net

  24. 24

    How to map URL path to physical path in asp.net website

  25. 25

    asp.net MVC saving relative path in database as not the full path

  26. 26

    ASP.NET Core 3.1ルーティング(Route、ActionName)のローカリゼーションを行う方法は?

  27. 27

    ASP.Net Core SAML authentication

  28. 28

    ASP.Net Core SAML authentication

  29. 29

    ASP.Net Core SAML authentication

ホットタグ

アーカイブ