资源无法找到MVC4

时间:2014-09-18 06:20:47

标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing

我已将我的网站上传到服务器上。并且发生了错误。我的网站网址为http://vintageoverseas.org/。这是一个网址,其网址是http://vintageoverseas.org/en/Blog,但是当我点击read more按钮Blog title然后The resource cannot be found.时,此操作名称为BlogPost,当我将其更改为Post

发生此错误
The view 'Post' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Post.aspx
~/Views/Home/Post.ascx
~/Views/Shared/Post.aspx
~/Views/Shared/Post.ascx
~/Views/Home/Post.cshtml
~/Views/Home/Post.vbhtml
~/Views/Shared/Post.cshtml
~/Views/Shared/Post.vbhtml 

我的控制器名称为Home,其代码为

  public ActionResult BlogPost(long? Id)
        {
            BlogModel blog = new BlogModel();
            blog = b.GetBlogDetail(Id.ToString());
            List<TagModel> tags = new List<TagModel>();
            tags = b.GetBlogTags(blog.blog_id.ToString());
            blog.tag_name_list = tags.Select(m => m.tag_name).ToList();
            List<ImageModel> image = new List<ImageModel>();
            image = b.GetBlogImages(blog.blog_id.ToString());
            blog.img_path_list = image.Select(m => m.path).ToList();
            blog.parent_cat_id = b.GetMainParent(blog.cat_id);
            return View(blog);
        }

视图名称为BlogPost

路由

 public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                name: "Custom",
                url: "en/{action}/{id}/{Title}",
                defaults: new { controller = "Home", action = "Index", 
                    id = UrlParameter.Optional, Title = UrlParameter.Optional, en = UrlParameter.Optional }
            );
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            ); 
        }

1 个答案:

答案 0 :(得分:0)

您确定您的BlogPost操作位于HomeController.cs中吗?还是有一个名为“en”的控制器?

您可能需要在第一条路线中使用{controller}参数,然后修改您的锚点以将控制器用作@Html.ActionLink("Read More...", "BlogPost", "ControllerName", new {id="123", null);

尝试使用路由调试器 - 安装后可以使用web.config开关打开和关闭它:https://www.nuget.org/packages/routedebugger