I have @Ajax.ActionLink call by which I am trying to pass data to controller and refresh partial view. When I click on the link instead of passing the data to the controller, it is redirecting me to the previous page.
Ajax code:
@Ajax.ActionLink(@mainType.Descr, "GetChosenFaqSubCategory", "FAQ",
new { @TabCode = @mainType.TabCode },
new AjaxOptions
{
UpdateTargetId = "reloadFaq",
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
})
Controller:
[HttpPost]
public ActionResult GetChosenFaqSubCategory(string TapCode)
{
string pFilter = "WebFaqCategoryCd=" + TapCode;
code...
return PartialView("GlobalFAQ", List);
}
As bundles I am loading:
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryunobtr").Include(
"~/Scripts/jquery-3.6.0.min.js"));
bundles.Add(new ScriptBundle("~/bundles/ajax").Include(
"~/Scripts/MicrosoftAjax*",
"~/Scripts/MicrosoftMvcAjax*"));
In the Web.config unobtrusive is allowed:
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
@Ajax.ActionLink(@mainType.Descr, "GetChosenFaqSubCategory", "FAQ",
new { @TabCode = @mainType.TabCode },
new AjaxOptions
{
UpdateTargetId = "reloadFaq",
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
})
You have @TabCode here but it would try to look for @TabCode in your parameters. Try it with "TabCode = @mainType.TabCode"
For better readability it looks like you're using an int to identify the Tab that is selected. TabId would probably be better when looking at it without documentation.