2008-11-27 80 views
0

我在幾乎空的ASP.NET MVC項目的Site.Master頁面中有下面的代碼。ASP.NET MVC文件夾控制器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的視圖文件夾。在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 

我錯過了什麼嗎?我需要在某處添加Feeds文件夾嗎? Feed是否需要到鏈接中列出的「Home」的位置?我甚至嘗試過,仍然有錯誤。

謝謝。

回答

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的,我認爲這正是阿德倫是試圖實現。 +1 – Franck 2008-11-27 13:56:06

9

您的控制器被稱爲「Home」,因此您的視圖應該位於Views/Home文件夾中,而不是Views/Feeds中。

該錯誤消息明確指出,它正在搜索〜/瀏覽/首頁/ FeedList.aspx和〜/瀏覽/首頁/ FeedList.ascx