且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将主文件夹中的视图重定向到同一文件夹中的另一个视图

更新时间:2023-11-23 10:31:34

在MVC中,您没有链接到 views ;你链接到动作



假设你有一个 NewPage 动作 HomeController

  public  ActionResult NewPage()
{
返回查看();
}

您可以使用网址.Action 帮助链接到它:

 <   a     href   ='  @ Url.Action(NewPage,Home)'    title   = PáginadePrueba >  TestPage <   / a  &GT; 跨度> 


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>

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>