1

In my MVC application I have a home controller and an index method in it. I have set the index methods as the default route in the RouteConfig file.

routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 

I'm using Angular JS in my application. I have defined a service and calling an action 'Clusters' in the home controller using $http.

app.service('homeService', function ($http) { this.getClusters = function () { var promise = $http.get("Clusters"); return promise; }; }); 

When I run the project and go to the default url [http://localhost:56698/] then http://localhost:56698/Clusters 404 not found exception occurred. But it is working if the url is http://localhost:56698/Home/Index. So my Angular js services are not working in the default url. How to fix this?

1 Answer 1

1

I think there is a problem with your javascript reference. you should use relative referencing like this :

<script src="@Url.Content("~/Scripts/angular.js")" type="text/javascript"></script> 

or you should change your clusters calling:( I assumed that your javascript code is located in your view)

 this.getClusters = function () { var promise = $http.get('@Url.action(Clusters,Your controller name)'); return promise; }; 
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your answer. But it is not worked. Reference to angular script is working in both url. But the url path 'Cluster' couldn't find in the default url [localhost:56698/].
@NOBLEM.O.:your welcome. I edited my answer base on your comment. please inform me if the new answer didn't work out.
Thank you pooria taghizadeh. The script is not in view file. So I cannot use @Url helper. I specified the controller name/action name in my script as you suggested. It worked. Thank you.
@NOBLEM.O. your welcome my friend. It was my pleasured to help you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.