asp.net 核心<a ASP-Controller = " " ASP-action= " " /> 从 jquery 运行



Net Core Mvc 6

我有一个类似的菜单

<li class="active nav-item h5"><a class="nav-link link-light aEmployer" asp-controller="Employer" asp-action="Index">Employer Setup</a></li>

返回View

我需要从Ajax调用它。

我播种这个和它说什么做

$.ajax({
// edit to add steve's suggestion.
//url: "/ControllerName/ActionName",
url: '<%= Url.Action("ActionName", "ControllerName") %>',
success: function(data) {
alert(data);
}
});

但在这种情况下,它返回一个PartialView。

我需要的是返回一个视图。。与用户单击选项菜单时返回的视图相同。

我需要的是类似('aa').click()的东西,但在这种情况下它不起作用。。。

这是一种称呼方式吗?

感谢

设置锚点元素的id属性:

<a id="employer-setup-link" class="nav-link link-light aEmployer" asp-controller="Employer" asp-action="Index">Employer Setup</a>

然后你可以做:

document.getElementById('employer-setup-link').click();

您也可以尝试:

window.location.href = document.getElementById('employer-setup-link').getAttribute('href');

最新更新