I have $get calling un my C#- MVC - Angular Js Proj . The url for request is incorrect for me and routing to the root proj folder on computer
$http.get('../Home/GetResponse').success(function (response) {
alert(response);
});
How I should write the url given that the my controller name is 'HomeController' and the function is 'GetResponse' ?
Thanks .
Use:
$http.get('Home/GetResponse').success(function (response) {
alert(response);
});
By using $http.get your are making a http request. This request can only be handled by a web server.
You should be hosting your asp.net MVC website in IIS and your $http.get should use an address along the lines of
http://localhost/Home/GetResponse
Right now you are trying to make an http request to a file on your file system which will not work. It would expect to find a folder called Home and a file called GetResponse.
Only IIS is able to load the http modules that can translate the route (in this case /Home/GetResponse) to an action on a controller.
$http.get(baseurl+'Home/GetResponse').success(function (response) {
alert(response);
});
just add baseurl in the layout page as
var baseurl=@Url.Content("~/");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.