简体   繁体   中英

The resource cannot be found MVC4

I have uploaded my site on server. And there is an error occurred. My site url is http://vintageoverseas.org/ . Here is a page that's url is http://vintageoverseas.org/en/Blog but when i click on read more button Blog title then The resource cannot be found. In this action name is BlogPost and when i change it to Post than this error is occurred as

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 

And my controller name is Home and it's code is

  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);
        }

And view name is BlogPost

And routing is

 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 }
            ); 
        }

Are you sure your BlogPost action resides in HomeController.cs? Or is there a controller named "en"?

You might need a {controller} parameter in your first route, and then modify your anchor to utilize controller as @Html.ActionLink("Read More...", "BlogPost", "ControllerName", new {id="123", null);

Try using route debugger - it can be turned on and off using a web.config switch after installed: https://www.nuget.org/packages/routedebugger

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM