1

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.

2
  • How to include what? Do you mean {appId} part of the URL? Commented Oct 22, 2019 at 10:55
  • yes , the url should be http://localhost:1001/admin/{adminID}/app/{appId}/user/Select type Commented Oct 22, 2019 at 11:07

1 Answer 1

1

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://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper?view=aspnetcore-3.0#asp-route-value

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.