Net Core Mvc 6
I have a Menu like this
<li ><a asp-controller="Employer" asp-action="Index">Employer Setup</a></li>
That returns a View
I need to call this from Ajax.
I sow this and what it says to do
$.ajax({
// edit to add steve's suggestion.
//url: "/ControllerName/ActionName",
url: '<%= Url.Action("ActionName", "ControllerName") %>',
success: function(data) {
alert(data);
}
});
But in this case, it returns a PartialView.
What I need is to return a View.. the same View that is returned when the user click the Option Menu.
What I need is something like ('aa').click()
but it does not work in this case...
It is a way to call it?
Thanks
CodePudding user response:
Set the id attribute of your anchor element:
<a id="employer-setup-link" asp-controller="Employer" asp-action="Index">Employer Setup</a>
And then you can do:
document.getElementById('employer-setup-link').click();
You can also try:
window.location.href = document.getElementById('employer-setup-link').getAttribute('href');