Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

asp.net mvc my route isn't working

Posted on 2013-12-25
6
318 Views
Last Modified: 2014-01-04
I am having a very strange issue with my route in my global.asax.cs page.  

In the mapRoute below, if I use action = "Grid", everything works.  I can use either url below to navigate to the correct controller.  If I use action="Angular", both urls below go to the Angular Controller.  I have no idea why this is, but it took me a very long time to find.

These only work when the global file has action="Grid", otherwise they always go to Angular
http://localhost:53233/Template/Grid
http://localhost:53233/Template/Angular


    public class TemplateController : Controller
    {
        //
        // GET: /Template/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Grid()
        {
            return View("Grid");
        }

        public ActionResult Angular()
        {
            return View("Angular");
        }

Open in new window


routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Template", action = "Grid", id = UrlParameter.Optional }// Parameter defaults

Open in new window

0
Comment
Question by:jackjohnson44
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 39739965
hi
Code you have given has build error.

Update with this:

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Template", action = "Grid", id = UrlParameter.Optional });// Parameter defaults

Open in new window


Comment out original one.
Create two views (Grid and Angular) inside
~\Views\Template\
path.

It is working for me.
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 39739966
simple way of creating view is:

inside Template controller, just right click on
View("Grid")
and select add view. It will take view name also automatically.

Same thing for Angular view also and RUN application.
0
 

Author Comment

by:jackjohnson44
ID: 39741151
Hi, thanks.  The compile error was because I choppped the last line.  It should have included a ");".  My code looks right and should work, but something is causing the issue I talked about above.  Any ideas how to diagnose this?
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 16

Accepted Solution

by:
Stephan earned 500 total points
ID: 39741273
This always helped me debug routes:
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx/

If I use action="Angular", both urls below go to the Angular Controller.

Do you have an angular controller or do you mean the method/action "Angular".
And where you do say action="Angular"? In a Html.ActionLink or something?

Maybe you could give us some more details in the result on how you are rendering this and what the results are. Maybe also add a screenshot of your project file with the controllers folder open.

Also, is there more than 1 route you specified or is this the only one?
0
 

Author Comment

by:jackjohnson44
ID: 39741823
All of my code is above.  I showed the Template controller and my single mapping.  Action comes from the map route.
0
 
LVL 16

Expert Comment

by:Stephan
ID: 39741926
I created a new MVC5 project with a templatecontroller (using your code) and the following mapRoute:

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

Open in new window


On the code part it is pretty thesame of what you have sent us, only I don't have any issues.
Which version of MVC are you using and which Visual studio version?

Currently only thing that I can think of is that there is something interferring with the code you have besides the code you posted.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question