Click here to Skip to main content
15,748,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I´m developing a MVC app just for learning purposes.
I added a new View in the /Views/Home directory, and I tried to access it from the Index View, but when I do it, get the error HTTP 404.

here´s the tag: href="~/Views/Home/NewPage" title="Página de Prueba">TestPage/a>

is it posible to do so ?. (add references between pages in the Home directory

I´m working with Visual Studio 2010 C#

What I have tried:

Just to check the functionality, I added another page, in the root directory of my app, and added another tag, (In the Index View) to see if it works, and it did.

My tag: href="../../ViewPage1.aspx" title="esta es otra página">Esta es otra página>
Updated 24-Feb-17 8:05am

1 solution

In MVC, you don't link to views; you link to actions.

Assuming you have a NewPage action on your HomeController:
public ActionResult NewPage()
    return View();
you can use the Url.Action helper to link to it:
<a href='@Url.Action("NewPage", "Home")' title="Página de Prueba">TestPage</a>
Share this answer
Miguel Altamirano Morales 24-Feb-17 14:36pm    
Thanks for your answer Richard, I DO have an ActionResult "NewPage" in my Home Controller.
I copied the code of the url.Action you sent me and I get the error "Invalid characters in the route path"
Now, if you see my question, I have another href tag to an aspx page that resides in my root directory, and I DON´T have an action in homecontroller, but it works fine !!!
Richard Deeming 26-Feb-17 11:12am    
The link that's working is linking to a WebForms page. WebForms pre-dates routing, so by default, you link directly to the page.

With MVC, you can only link to an action, not a view.

If you're getting an error, double-check your RouteConfig class, and the generated URL.
Miguel Altamirano Morales 26-Feb-17 22:33pm    
Thanks again, Richard. I noticed that the generated URL is :


So, Im´m thinking that maybe the '%22' characters (they´re supposed to be quotes) are the ones causing the error. This address is exactly how it is showed in the navigator. I´m going to try to replace those characters using their ascii codes in a string, or, there is a reason why my app is doin this ?, some kind of configuration or something ?.

Please excuse me if I sound too naive. This is my first MVC app. I´m very aware I have to go deeper in studying this. I don´t know how to do even what you are telling men.
Richard Deeming 27-Feb-17 5:33am    
That's odd. Are you definitely generating the link in an MVC view, or is it a WebForm?
Miguel Altamirano Morales 27-Feb-17 12:28pm    
The two '<a' tags are located in the Index.aspx page in the Views/Home Folder. One of them points to an aspx page in the root directory of the app (href="../../ViewPage1.aspx") and it Works fine.

The other tries to navigate to an aspx page in the same Views/Home directory and it fails. Originally said that the resource is not found ((~/Views/Home</TestPage.aspx) and with the @url.Action helper it generates invalid characters. Yes, it´s a link between views.

I´m going to go deeper in my studies of the subject and see if I can solve this while I´m learning more. Sometimes that happens.

Thank you very much Richard !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900