gpt4 book ai didi

asp.net-mvc - 在 MVC 5 中创建了一个新 View ,在 HTTP 404 中打开新 View 结果

转载 作者:行者123 更新时间:2023-12-04 23:02:09 26 4
gpt4 key购买 nike

当我打开默认的 MVC View (索引和创建)时,它工作正常,我可以添加数据并从数据库中获取数据。当我创建一个新 View 时,它不起作用。它获取 Http 404。
即使我复制了创建 View ,也只是使用不同的文件名。

错误信息:

Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.



我遵循了有类似问题的人的一些论坛建议,但它不起作用。

我使用 MVC 5、EF6、VS2013,我的数据库是 MS-sql。

感谢任何为我指明正确方向的建议。
谢谢!

最佳答案

您应该通过 访问 View 行动方法。因此,如果您在 ~/Views/Home/AboutMe.cshtml 中创建了新 View , 您应该在 HomeController 中添加这样的操作方法.

public class HomeController : Controller
{
public ActionResult AboutMe()
{
return View();
}
}

现在你可以像 http://yourServerName/yourAppName/Home/AboutMe 一样访问这个

如果您想在不同的 Controller 中使用您的操作方法,您可以指定完整的 View 路径。例如:如果您想将操作方法​​添加到您的帐户 Controller ,
public class AccountController : Controller
{
public ActionResult AboutMe()
{
return View("~/Views/Home/aboutme.cshtml");
}
}

关于asp.net-mvc - 在 MVC 5 中创建了一个新 View ,在 HTTP 404 中打开新 View 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com