我正在使用一个MVC Web应用程序,其中一个页面使用javascript文件作为数据。
I have the TournamentInfo.js file in a folder called "Scripts"
I have the TournamentController.cs file in a folder called "Controllers"
I have the TourneyInfo.cshtml file in a folder called "Tourneys" that is in a folder called "Views"
当我尝试运行项目时,我收到以下错误:
[Htpp Exception] The controller for path '/Tourneys/TourneyInfo' was not found or does not implement IController
我的项目中有另一个页面,它使用相同的格式(javascript文件,控制器文件和视图文件)设置,并且该页面没有问题。我找不到会导致我收到的错误的差异。
有关我应该在我的锦标赛页面上寻找解决问题的建议吗?
*如果您想查看每个文件的代码,请告诉我们。我不确定它是否相关,因为我的其他页面使用这种格式是有效的。
Javscript文件:
function tournamentpageModel() {
var self = this;
self.Tournaments = ko.observableArray([]);
}
function TourneyInfo(_name, _date, _location, _pattern, _avg, _finish, _ttlentries) {
var self = this;
self.Name = ko.observable(_name);
self.Date = ko.observable(_date);
self.Loc = ko.observable(_location);
self.Pattern = ko.observable(_pattern);
self.Avg = ko.observable(_avg);
self.Finish = ko.observable(_finish);
self.Entries = ko.observable(_ttlentries);
}
var viewTModel = new tournamentpageModel();
viewTModel.Tournaments.push(new TourneyInfo("South Regional", "May 9-10, 2014", "Rocky Mount, NC", "Chameleon (41ft)", "167.75", "70th", "75"));
viewTModel.Tournaments.push(new TourneyInfo("South Regional", "March 7-9, 2014", "Pensacola, FL", "Badger (52ft)", "215.75", "17th", ""));
viewTModel.Tournaments.push(new TourneyInfo("South Regional", "", "Pensacola, FL", "", "", "", ""));
viewTModel.Tournaments.push(new TourneyInfo("South Regional", "", "Canton, GA", "Viper (39ft)", "215.75", "14th", ""));
$(function () {
ko.applyBindings(viewTModel);
})
控制器:
using PracticeApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PracticeApp.Controllers
{
public class TournamentController : Controller
{
public ActionResult TourneyInfo()
{
return View();
}
}
}
查看:
<script src="@Url.Content("~/Models/TournamentInfo.js")" type="text/javascript"></script>
@{
ViewBag.Title = "Tournaments";
}
<hgroup class="title">
<h1>@ViewBag.Title</h1>
</hgroup>
<table id="sponsorTable">
<!-- Todo: Generate table body -->
<tbody data-bind="foreach: TourneyInfo">
<tr>
<th>Tournament Name</th><th>Date</th><th>Location</th><th>Oil Pattern</th><th>Quailfying Avg</th><th>Finished</th><th>Total Entries</th>
</tr>
<tr>
<td class="sTableInfo" data-bind="text: Name"></td>
<td class="sTableInfo" data-bind="text: Date"></td>
<td class="sTableInfo" data-bind="text: Loc"></td>
<td class="sTableInfo" data-bind="text: Pattern"></td>
<td class="sTableInfo" data-bind="text: Avg"></td>
<td class="sTableInfo" data-bind="text: Finish"></td>
<td class="sTableInfo" data-bind="text: Entries"></td>
</tr>
</tbody>
</table>
共享布局....包含导航菜单的操作链接。除锦标赛链接外,他们都有效。它们都在重载中使用相同的格式(“超链接文本”,“文件名”,“文件夹名称”):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Atlas Web Pages</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script src="@Url.Content("~/Scripts/knockout-2.1.0.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.7.1.js")" type="text/javascript"></script>
</head>
<body>
<header id="header">
<div class="web-header">
<div class="logo-image">
<img src="~/Images/Atlas.png" style="float: left" height="125" width="150" alt="Atlas Logo" />
<img style="vertical-align:top" src="~/Images/WebPageLogo.png" height="85" width="820" alt="Atlas Logo" />
<div style="color:#FFF">*A southpaw's approach to bowling*</div>
</div>
<div class="float-right">
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("The Team", "About", "About")</li>
<li>@Html.ActionLink("Current Line-Up", "CurrentList", "Current")</li>
<li>@Html.ActionLink("Retired Equipment", "RetiredList", "Retired")</li>
<li>@Html.ActionLink("Tournaments", "TourneyInfo", "Tourneys")</li>
<li>@Html.ActionLink("Bowling Videos", "Videos", "Video")</li>
<li>@Html.ActionLink("Sponsors", "Sponsors", "Sponsor")</li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div id="footer">
<div class="content-wrapper">
<div class="float-left">
<p>© @DateTime.Now.Year: Southpaw Web Solutions™ - Email: jmilam90@gmail.com</p>
<p>Stylized drawing of the god, Atlas, courtesy of shutterstock</p>
</div>
<div id="follow-icons">
<a href ="www.facebook.com/jmilam90"><img src="~/Images/FBIcon.png" alt="Follow on Facebook" height="40" width="40" /></a>
<a href ="www.twitter.com/jmilam900"><img src="~/Images/TwitIcon.png" alt="Follow on twitter" height="40" width="40" /></a>
</div>
</div>
<table id="logo-table">
<tr>
<td>
<img src="~/Images/MBW.png" width="99" height="60" alt="McCorveys Bowling World Logo" />
</td>
<td>
<img src="~/Images/EboniteLogo.png" width="93" height="60" alt="Ebonite Logo" />
</td>
<td>
<img src="~/Images/TrackLogo.png" width="152" height="60" alt="Track Bowling Logo" />
</td>
<td>
<img src="~/Images/HammerLogo.png" width="100" height="60" alt="Hammer Bowling Logo" />
</td>
<td>
<img src="~/Images/ColumbiaLogo.png" width="123" height="60" alt="Columbia 300 Logo" />
</td>
<td>
<img src="~/Images/PBALogo.png" width="60" height="60" alt="PBA Logo" />
</td>
</tr>
</table>
</div>
</footer>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
答案 0 :(得分:0)
约定是路径使用控制器名称的前缀,因此您应该导航到:
/Tournament/TourneyInfo/
而不是:
/Tourneys/TourneyInfo/
您可能会发现Glimpse可用于确定在报告故障之前尝试了哪些路线:
修改:另请参阅以下评论。另一个问题是视图的位置 - 默认情况下,视图需要位于Views\<ControllerName>\
文件夹中,例如Views\Tournament\
。