将主文件夹中的视图重定向到同一文件夹中的另一个视图 [英] Redirect a view in the home folder to another in the same folder
问题描述
我正在开发一个MVC应用程序仅用于学习目的。
我在/ Views / Home目录中添加了一个新视图,我试图从索引视图中访问它,但是当我做到这一点,得到错误HTTP 404.
这里的标签:href =〜/ Views / Home / NewPagetitle =PáginadePrueba> ; TestPage / a>
是否可以这样做? (在主目录中的页面之间添加引用
我正在使用Visual Studio 2010 C#
我尝试了什么:
为了检查功能,我在我的应用程序的根目录中添加了另一个页面,并添加了另一个页面标签,(在索引视图中)看它是否有效,它确实有效。
我的标签:href =../../ ViewPage1.aspx title =esta esotrapágina> Esta esotrapágina>
在MVC中,您没有链接到 views ;你链接到动作。
假设你有一个NewPage
动作HomeController
:
public ActionResult NewPage()
{
返回查看();
}您可以使用
网址.Action
帮助链接到它:
< a href =' @ Url.Action(NewPage,Home)' title = PáginadePrueba < span class =code-keyword>> TestPage < / a > 跨度>
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 aNewPage
action on yourHomeController
:
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>
这篇关于将主文件夹中的视图重定向到同一文件夹中的另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!