I have an ASP.Net Core MVC5 project with a view containing partialViews. In it I show a Bootstrap modal that loads data from a record in context. I need the identifier of this record to be passed as a parameter in an <a>
tag that redirects to another action of the same Controller.
I tried to mount it like this:
<a asp-controller="Controller" asp-action="Action" asp-route="@ViewBag.Value" >
<i ></i>
Button
</a>
However it doesn't work, it doesn't recognize the ViewBag.
I also tried with Onclick script, like this, but the id
parameter arrives as null.
$('#idA').attr('action', '/Controller/Action/'@ViewBag.id);
Has anyone done something like this or can help me?
CodePudding user response:
You can use asp-route-id
<a asp-controller="Controller" asp-action="Action" asp-route="@ViewBag.Value" asp-route-id="@ViewBag.id" >
<i ></i>
Button
</a>
CodePudding user response:
You can use javascript or jquery for getting the values and ajax to post to the controller, something like this: