Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have 3 Asp.Net MVC controllers and all have one Index view. I am trying to do angularjs routing for the actions. Assuming the urls are like

http://localhost/Budget/Index (default controller)
http://localhost/Vacations/Index
http://localhost/CompanyTests/Index 

In all three of my Index.cshtml files I've [ng-view] and have setup corresponding html files with angular controllers. In my app.js main module, I have a default route that opens budgetindex.html when the url is /#/. I have configured all angular routes.

Assuming I'm on this URL:

http://localhost/CompanyTests/Index/#/tests

My angular route opens up companytestindex.html, I have a form that submits a POST request on one of the action on CompanyTests MVC controller and I'm returning RedirectToAction Index after processing the file upload which takes me to the url below

http://localhost/CompanyTests/Index 

And after angular route takes control it rightly considers it as /#/ and executes the default route which is not what i want. I want the user to be direct to same screen where he uploaded the file.

The summary of the question is, for multiple asp.net mvc controllers i have angular routes and my html templates post data to asp.net mvc actions. After executing the action it returns back to Controller/Index and angular considers it as the default endpoint and opens up the incorrect html.

I have already spent days trying to look for articles explaining angularjs routing with multiple asp.net mvc controllers but haven't found any help. I just need a little direction here.

Thanks

share|improve this question
    
What you are doing after successfully posting data on action. Are you doing window.location.href ="new url" or redirecting to a certain route in Angular JS ? – Ankush Jain 20 hours ago
    
I'm directly posting from .html file to ASP.NET MVC action which returns the Index View. URL ends with / so angular route considers it as default route. I'm missing /#/someroute when action returns the view. – Ali Baig 20 hours ago
1  
You should not return view directly, instead you shoul return json and based on success and failure..you should redirect user to some angular route..This will more clean and understandable way of doing something. – Ankush Jain 20 hours ago
1  
for RedirectToAction I guess you won't be able to set custom parameters , I guess you require Redirect method that contains your /#/someroute in url and then angular will identify proper view when its on client side. – vishal sharma 19 hours ago
    
@vishalsharma That's definitely the easiest way out right now, thanks. – Ali Baig 18 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.