当前位置:  开发笔记 > 后端 > 正文

ASP.NET MVC文件夹控制器Html.ActionLink

如何解决《ASP.NETMVC文件夹控制器Html.ActionLink》经验,为你挑选了2个好方法。

我在几乎空的ASP.NET MVC项目的Site.Master页面中有以下代码.

  • <%= Html.ActionLink("Home", "Index", "Home")%>
  • <%= Html.ActionLink("Feed List", "FeedList", "Home")%>
  • <%= Html.ActionLink("Monitored Feeds", "MonitoredFeeds", "Home")%>
  • <%= Html.ActionLink("About", "About", "Home")%>
  • 我还没有添加任何文件夹到名为Feeds的Views文件夹.在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.b__10() +39
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +385
       System.Web.Mvc.<>c__DisplayClass15.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"的位置?我甚至试过了,但仍然得到了错误.

    谢谢.



    1> Franck..:

    您的控制器名为"Home",因此您的视图应位于Views/Home文件夹中,而不是Views/Feeds中.

    错误消息清楚地表明它正在搜索〜/ Views/Home/FeedList.aspx和〜/ Views/Home/FeedList.ascx



    2> Todd Smith..:

    创建一个FeedsController.cs并将它们移动到该控制器

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

    然后修复这些以使用Feeds控制器

  • <%= Html.ActionLink("Feed List", "FeedList", "Feeds")%>
  • <%= Html.ActionLink("Monitored Feeds", "MonitoredFeeds", "Feeds")%>
  • 推荐阅读
    ar_wen2402851455
    这个屌丝很懒,什么也没留下!
    DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
    Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有