i’m trying to call action comment on snippets controller but for some reason the ajax call invokes the index action on home controller.
Ajax call
$(".test").click(function (evt) {
var urlData = $(this).attr("href");
var url = urlData.split("?")[0]; //URL is /snippet/comment?comID=2
var commentID= urlData.split("=")[1] //
$.ajax({
Url: url,
type: 'Get',
date: { comID: commentID},
success: function (data) {
$("#Comments").html(data);
}
});
evt.preventDefault();
});
Routes
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
You have a typo,
Urlshould start with lowercaseu. Alsodateshould bedata:By the way all the string splitting stuff’s probably useless. Why don’t you simply use the url of the anchor that you are AJAXifying: