[null, null, {"document_url": "https://codedump.io/share/8hw8v2KbUDwo/1/fix-error-with-route-url-in-aspnet-mvc-5", "unformatted_src": "https://i.stack.imgur.com/sjQOn.png", "src": "https://i.stack.imgur.com/sjQOn.png", "formatted_filename": "sjQOn", "alt_text": "enter image description here"}, null, {"document_url": "https://codedump.io/share/8hw8v2KbUDwo/1/fix-error-with-route-url-in-aspnet-mvc-5", "unformatted_src": "https://i.stack.imgur.com/JRi9R.png", "src": "https://i.stack.imgur.com/JRi9R.png", "formatted_filename": "JRi R", "alt_text": "enter image description here"}, null, {"document_url": "https://codedump.io/share/8hw8v2KbUDwo/1/fix-error-with-route-url-in-aspnet-mvc-5", "unformatted_src": "https://i.stack.imgur.com/4wr4v.png", "src": "https://i.stack.imgur.com/4wr4v.png", "formatted_filename": "wr v", "alt_text": "enter image description here"}, null, {"document_url": "https://codedump.io/share/8hw8v2KbUDwo/1/fix-error-with-route-url-in-aspnet-mvc-5", "unformatted_src": "https://i.stack.imgur.com/brqRg.png", "src": "https://i.stack.imgur.com/brqRg.png", "formatted_filename": "brqRg", "alt_text": "enter image description here"}, null, null]
Arianit - 2 years ago 167

Fix error with route url in Asp.Net MVC 5

I have this datamodel: so one Project has many Milestones.
What I did is this: when I go to the detail of a specific Project, I can add/create Milestones for it, like in the picture: When I click "Create Milestone" I navigate to the View where I can create the milestone for this specific Project, when I click save, it will automatically be saved for this project. Here the HttpPost method:

Here is a screenshot of the CreateMilestone View, and focus on the url (it's localhost:xxxxx/Projects/CreateMilestone/3002). The id parameter in the CreateMilestone method is for the Project ID, and in the url the id (3002) is also for the project. I'm trying to make the app to navigate to the Details view of that specific Project I just added a milestone, which I do actually!
And as you see it works: But: look at the url! Instead of being localhost:xxxxx/Projects/Details/3002 it is: http://localhost:55623/Projects/Details/3002?Milestones=System.Collections.Generic.HashSet%601%5BTheProjectManager.Models.Milestone%5D&Users=System.Collections.Generic.HashSet%601%5BTheProjectManager.Models.ApplicationUser%5D&ProjectName=Testing&Description=Testing%20data

So, how can I make the url be like: localhost:xxxxx/Projects/Details/3002 when I navigate to the details view after adding a new milestone?

the Get Details:

and the Get CreateMilestone: 
Instead of return RedirectToAction("Details",forProject); try this return RedirectToAction("Details", new { id = id });

Email codedump link for Fix error with route url in Asp.Net MVC 5

