【发布时间】:2014-09-18 06:20:46
【问题描述】:
我已将我的网站上传到服务器。并且发生了错误。我的网站网址是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 }
);
}
【问题讨论】:
-
你有一个名字属性来装饰你的动作吗?或者您是来自
Post操作的RedirectToAction呼叫吗? -
此
en用于路由@AndreiV,并且没有名为“post”的操作 -
您是否考虑过名称为“Post.XXX”的视图不存在的可能性?看起来错误消息是这样说的......您的要求并不完全清楚 - 我假设您知道默认视图名称是操作的名称......所以不确定您正在寻找什么帮助。
标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing