在MVC 5中创建一个新的观点,在HTTP 404打开新的查看结果 [英] Created a new view in MVC 5, opening the new view results in HTTP 404

查看:470
本文介绍了在MVC 5中创建一个新的观点,在HTTP 404打开新的查看结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开默认的MVC视图(index和create),它做工精细,我可以添加数据和从数据库中获取数据。当我创建一个新的观点它不工作。它得到HTTP 404。
这是即使我重复创建视图,只能用不同的文件名。

When I open the default MVC views(index and create) it work fine, I can add data and get data from the database. When I create a new view it don't work. It gets Http 404. This is even if I duplicate the create view, only with a different file name.

错误消息:

在'/'应用程序的服务器错误。
  资源无法找到。
  说明:HTTP 404。您正在寻找(或它的一个依赖)可能已被删除的资源,更名或暂时不可用。请检查以下URL并确保其拼写正确。

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

I have follow some forum suggestions from people with similar problems, but it don't work.

我使用MVC 5,EF6,VS2013和我的数据库是一个MS-SQL。

I use MVC 5, EF6, VS2013 and my DB is a MS-sql.

这点我在正确的方向有什么建议是AP preciated。
谢谢!

Any suggestions that point me in the right direction is appreciated. Thanks!

推荐答案

您应该通过行动访问视图方式。所以,如果您创建新视图〜/查看/主页/ AboutMe.cshtml ,您应该添加一个操作方法是这样在你的 HomeController的

You should be accessing the view through an action method. So If you created your new view in ~/Views/Home/AboutMe.cshtml, You should add an action method like this in your HomeController.

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

现在你可以访问此像的http:// yourServerName / yourAppName /主页/ AboutMe

如果你想有一个不同的控制器动作方法,您可以指定众目睽睽路径。例如:如果你想操作方法添加到您的帐户控制器,

If you want to have your action method in a different controller, You can specify the full view path. Ex : IF you want to add the action method to your Account controller,

public class AccountController : Controller
{
   public ActionResult AboutMe()
   {
      return View("~/Views/Home/aboutme.cshtml");
   }
}

这篇关于在MVC 5中创建一个新的观点,在HTTP 404打开新的查看结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆