2008-11-27 2 views
0

У меня есть следующий код на моей странице Site.Master почти пустого проекта ASP.NET MVC.ASP.NET MVC Folder Controller Html.ActionLink

<li> 
    <%= Html.ActionLink("Home", "Index", "Home")%> 
</li> 
<li> 
    <%= Html.ActionLink("Feed List", "FeedList", "Home")%> 
</li> 
<li> 
    <%= Html.ActionLink("Monitored Feeds", "MonitoredFeeds", "Home")%> 
</li> 
<li> 
    <%= Html.ActionLink("About", "About", "Home")%> 
</li> 

Я не добавил ничего, кроме Папки, в Папку видов, называемую Feeds. В папке «Каналы» у меня есть два вида; FeedList.aspx и MonitoredFeeds.aspx. Я также добавил следующий код в HomeController, как показано ниже.

[HandleError] 
public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     ViewData["Title"] = "The Reporter"; 
     ViewData["Message"] = "Welcome to The Reporter."; 
     return View(); 
    } 

    public ActionResult About() 
    { 
     ViewData["Title"] = "About Page"; 
     return View(); 
    } 

    public ActionResult FeedList() 
    { 
     ViewData["Title"] = "Feed List"; 
     return View(); 
    } 

    public ActionResult MonitoredFeeds() 
    { 
     ViewData["Title"] = "Monitored Feeds"; 
     return View(); 
    } 
} 

Независимо от того, что я делаю, всякий раз, когда я нажимаю ссылки на страницы, отображается следующая ошибка.

Server Error in '/' Application. 
-------------------------------------------------------------------------------- 

The view 'FeedList' or its master could not be found. The following locations were searched: 
~/Views/Home/FeedList.aspx 
~/Views/Home/FeedList.ascx 
~/Views/Shared/FeedList.aspx 
~/Views/Shared/FeedList.ascx 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The view 'FeedList' or its master could not be found. The following locations were searched: 
~/Views/Home/FeedList.aspx 
~/Views/Home/FeedList.ascx 
~/Views/Shared/FeedList.aspx 
~/Views/Shared/FeedList.ascx 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[InvalidOperationException: The view 'FeedList' or its master could not be found. The following locations were searched: 
~/Views/Home/FeedList.aspx 
~/Views/Home/FeedList.ascx 
~/Views/Shared/FeedList.aspx 
~/Views/Shared/FeedList.ascx] 
    System.Web.Mvc.ViewResult.FindView(ControllerContext context) +493 
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +199 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ActionResult actionResult) +105 
    System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +39 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +385 
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionResultWithFilters>b__12() +61 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ActionResult actionResult, IList`1 filters) +386 
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +736 
    System.Web.Mvc.Controller.ExecuteCore() +180 
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +96 
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +36 
    System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +377 
    System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +71 
    System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +36 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75 




-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 

Я что-то пропустил? Нужно ли мне куда-то добавлять папку «Каналы»? Нуждаются ли каналы в том, где у меня есть «Главная», указанная в ссылках? Я даже пробовал это и до сих пор получил ошибку.

Спасибо.

ответ

8

Создать FeedsController.cs и переместить их к этому контроллеру

public ActionResult FeedList() 
{ 
    ViewData["Title"] = "Feed List"; 
    return View(); 
} 

public ActionResult MonitoredFeeds() 
{ 
    ViewData["Title"] = "Monitored Feeds"; 
    return View(); 
} 

Затем закрепите их, чтобы использовать контроллер ПОДАЧИ

<li> 
    <%= Html.ActionLink("Feed List", "FeedList", "Feeds")%> 
</li> 
<li> 
    <%= Html.ActionLink("Monitored Feeds", "MonitoredFeeds", "Feeds")%> 
</li> 
+0

Да, это на самом деле лучшее решение, потому что каналы не имеют ничего общего с HomeController, и я думаю, что это именно то, что было Adron пытаясь добиться. +1 – Franck 2008-11-27 13:56:06

9

Ваш контроллер называется «Главная», поэтому ваши представления должны находиться в папке «Виды/Главная», а не в «Представлениях/Каналах».

Сообщение об ошибке четко говорится, что он ищет ~/Views/Home/FeedList.aspx и ~/Views/Home/FeedList.ascx