1

Net Core Mvc 6

I have a Menu like this

<li class="active nav-item h5"><a class="nav-link link-light aEmployer" 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

2
  • Can you please explain what you are trying to achieve? Do you want to call an action that returns a PartialView using ajax and then display the PartialView? Commented Sep 27, 2022 at 21:18
  • I need to return a View.... the same View that is rendered when you click... Thanks Commented Sep 27, 2022 at 21:19

1 Answer 1

1

Set the id attribute of your anchor element:

<a id="employer-setup-link" class="nav-link link-light aEmployer" 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');
Sign up to request clarification or add additional context in comments.

3 Comments

IT does not work... <a> does not have a click() event.. so when you call .click(); nothing happend
I added another possible solution to my answer.

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.