質問

ほとんど空のASP.NET MVCプロジェクトのSite.Masterページに次のコードがあります。

<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フォルダーには2つのビューがあります。 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フォルダーをどこかに追加する必要がありますか?フィードは「ホーム」がある場所に移動する必要がありますかリンクにリストされていますか?私も試してみましたが、それでもエラーが発生します。

ありがとう。

役に立ちましたか?

解決

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>

他のヒント

コントローラーは「ホーム」と呼ばれるため、ビューはビュー/フィードではなく、ビュー/ホームフォルダーにある必要があります。

エラーメッセージは、〜/ Views / Home / FeedList.aspxおよび〜/ Views / Home / FeedList.ascxを検索していることを明確に示しています

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top