我正在做一个MVC教程和我在做一个真正的基本Web应用程序的一部分。MVC Web应用程序错误HTTP 404
这是我的控制器文件夹内的控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace FirstMVCApplication.Controllers
{
public class HomeContoller : Controller
{
//
// GET: /HomeContoller/
public ActionResult Index()
{
int hour = DateTime.Now.Hour;
ViewBag.Greeting =
hour < 12
? "Good Morning. Time is" + DateTime.Now.ToShortTimeString()
: "Good Afternoon. Time is " + DateTime.Now.ToShortTimeString();
return View();
}
}
}
这是我的看法查看文件夹内:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@ViewBag.Greeting (<b>From Index View</b>)
</div>
</body>
</html>
进出口使用剃刀。
而当我执行它它返回一个HTTP 404资源未找到。它是一个空Web MVC-4应用程序。
EDIT RouteConfig
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace FirstMVCApplication
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
此视图必须保留在Views/Home文件夹中。你应该在浏览器中发布路由配置文件和你正在调试的url。 – Fals
http:// localhost:“Port”/ – Nickso
这里有两点:1 - 4XX错误,意味着你(用户,而不是服务器)做错了什么。 2- 404 =您请求的资源找不到,可能是您使用的是错误的网址。请向我们展示在浏览器中显示的网址 –