I am learning web development. And I just want to make a simple AJAX GET call in ASP.Net MVC Application and I want visualize how it works. But I am not able to do so. I am a beginner and I could have done any silly mistakes. But as of now there are no errors in my code.
Below is what I have:
So, I have a Index.cshtml
file which is already loaded. Now in that page I want to make an Ajax GET call
to one of the function
that I have written in the HomeController
and action name is Test
. I just want to hit the breakpoint in that Test Action
of Homecontroller and return something back to the Success
of AJAX Call.
In HomeController I have below Action
[HttpGet]
public ActionResult Test()
{
return View("hello");
}
jQuery
$.ajax({
url: '/Home/Test',
type: 'GET',
success: function (html) {
alert(html);
},
error: function (error) {
$(that).remove();
DisplayError(error.statusText);
}
});
}
Confusion: Do I need to create a cshtml
for Test
. But I actually do not want that. I just want the Test
Action to return me one data. And I will display that data in my Already opened Index.csthml
file.
Error: No error but I am not able to hit the breakpoint in Test Action
of controller. Kindly note that Success
of AJAX is hitting but I do not see any data. But I am sure it did not hit the test Action breakpoint.