这是我的主屏幕:Visual Studio中:在“/” Application.The资源服务器错误无法找到
当我打的Log On
右侧,我达到这个:
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.
Requested URL: /HelloWorld/LogOn
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
这是我的项目在Visual Studio 2012的层次结构:
这是_Layout.cshtml
内容:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
</head>
<body>
<div class="page">
<header>
<div id="title">
<h1>Welcome to our MVC Movies Application
</h1>
</div>
<div id="logindisplay">
<!-- My TEST Comment -->
<!--
From here we go into to log-on page , furthermore if the user is
not listed , then we go straight into registration
-->
[ <a href="/HelloWorld/LogOn">Log On</a> ] @*This is just a non-working stub that would be changed later on*@
</div>
<nav>
<ul id="menu">
<!-- format is as follows
[the name of the presented tab]
[the name of the file in the Search Solution]
[the folder in Search Solution where the file above is located]
-->
<li>@Html.ActionLink("Home Tab", "Index", "Movies")</li>
<li>@Html.ActionLink("Search Tab", "SearchIndex", "Movies")</li>
<li>@Html.ActionLink("Hello World Tab", "Index", "HelloWorld")</li>
</ul>
</nav>
</header>
<section id="main">
@RenderBody()
</section>
<footer>
</footer>
</div>
</body>
</html>
这是LogOn.cshtml
内容:
@model Mvc3ToolsUpdateWeb_Default.Models.LogOnModel
@{
ViewBag.Title = "LogOn";
}
<h2>Log On</h2>
<p>
Please enter your user name and password. @Html.ActionLink("Register", "Register") if you don't have an account.
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")
@using (Html.BeginForm()) {
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
}
任何想法,我究竟错在这里做什么?什么导致404?
我想这东西是错误的布局文件的路径:
<a href="/HelloWorld/LogOn">Log On</a>
非常感谢
编辑:
HelloWorldController.cs:
using System.Web;
using System.Web.Mvc;
namespace MvcMovie.Controllers {
public class HelloWorldController : Controller {
public ActionResult Index() {
return View();
}
public ActionResult Welcome(string name, int numTimes = 1) {
ViewBag.Message = "Hello " + name;
ViewBag.NumTimes = numTimes;
return View();
}
}
}
你有一个'HelloWorldController'和一个名为'LogOn'的方法吗? – CodeCaster
@CodeCaster:我有控制器,但没有方法。我在帖子中编辑了代码。 – ron
既然你打电话给'/ HelloWorld/LogOn',你必须。你确定'LogOn'需要这个路径,或者你可以改变它指向实际上包含'LogOn'方法的控制器吗? – CodeCaster