我正在做一個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 =您請求的資源找不到,可能是您使用的是錯誤的網址。請向我們展示在瀏覽器中顯示的網址 –