jackjohnson44
asked on
asp.net mvc my route isn't working
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
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");
}
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Template", action = "Grid", id = UrlParameter.Optional }// Parameter defaults
simple way of creating view is:
inside Template controller, just right click on
Same thing for Angular view also and RUN application.
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.
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All of my code is above. I showed the Template controller and my single mapping. Action comes from the map route.
I created a new MVC5 project with a templatecontroller (using your code) and the following mapRoute:
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.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Template", action = "Angular", id = UrlParameter.Optional }
);
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.
Code you have given has build error.
Update with this:
Open in new window
Comment out original one.
Create two views (Grid and Angular) inside
~\Views\Template\
path.
It is working for me.