0

I have this view method witch required 2 arguments

[Route("chatbot/{chatbotId}/intents/{intentId}")]
public IActionResult Intents(int chatbotId, int intentId)
{
    return View();
}

The question is how can I pass the argument from ASP.NET Core core to it?

<a class="nav-link text-dark" asp-area="" 
      asp-controller="Chatbot" asp-action="Intents">Intents</a>
2
  • 1
    asp-route-chatbotId="..." etc? Commented Mar 12, 2021 at 3:00
  • WOOOOOOOOOOOOOOOT.... this is amazing, I didnt know i could simply do this. wow thank you, i really didnt know you could build arguments like this. But yeah this is defintily what I was looking for Thank you. If you want to answer it i will mark it as an answer. Commented Mar 12, 2021 at 3:06

2 Answers 2

1

You can also use "asp-all-route-data". So you can name your route like the following:

[Route("chatbot/intents/", Name="intents")]
public IActionResult Intents(int chatbotId, int intentId)
{
    return View();
}

And in the .cshtml file:

@{
var parms = new Dictionary<string, int>
            {
                { "chatbotId", 1 },
                { "intentId", 1 }
            };
}

<a asp-route="intents"
   asp-all-route-data="parms">Intents</a>

For more help, see this link.

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

Comments

1

Firstly,If you want to use asp-route-xxx as Jeremy Lakeman said,you need to change your Route like this:

[Route("chatbot/intents")]

And <a> link can be like this:

<a class="nav-link text-dark" asp-area="" asp-controller="Chatbot" asp-action="Intents" asp-route-chatbotId="1" asp-route-intentId="2">Intents</a>

If you change your route like chatbot/intents,it means chatbotId or intentId is not required in the route.

If you don't want to change Route [Route("chatbot/{chatbotId}/intents/{intentId}")].You can use href to replace taghelper(I use fake data,1 as chatbotId,2 as intentId in the example):

<a class="nav-link text-dark" href="/Chatbot/1/Intents/2">Intents</a>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.