Asp.net 同一操作返回的视图外观不同

Asp.net 同一操作返回的视图外观不同,asp.net,asp.net-mvc-4,Asp.net,Asp.net Mvc 4,我写了一个简单的网页类博客,我被以下问题阻止了。 在_Layout.cshtml中的Views/Shared中,我定义了页面的布局 我的路由规则是这样的 routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "paging", // Route name "Home/GetArticleListForCategory/{id}/{pageNo}", // URL with parameters new { con

我写了一个简单的网页类博客,我被以下问题阻止了。 在_Layout.cshtml中的Views/Shared中,我定义了页面的布局

我的路由规则是这样的

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"paging", // Route name
 "Home/GetArticleListForCategory/{id}/{pageNo}", // URL with parameters
 new { controller = "Home", action = "GetArticleListForCategory", id = UrlParameter.Optional, pageNo = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
 "Default", // Route name
 "{controller}/{action}/{id}", // URL with parameters
  new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
  );
当我从链接运行操作时 http://localhost:3282/Home/GetArticleListForCategory/1 页面显示正确

当我从链接运行操作时 http://localhost:3282/Home/GetArticleListForCategory/1/1 页面看起来“原始”,页面上没有布局,没有图像等。我比较了从两个链接返回的html,但它们是相同的。 控制器操作如下所示:

public ActionResult GetArticleListForCategory(int id,int pageNo = 1)
{

    int articlesPerPageNo = ConfigurationHelper.NoOfArticlePerPage;
    int totalNoOfArticles;
    List<PostShort> listOfPostforCategory = GetListOfShortArticles(pageNo,articlesPerPageNo ,out totalNoOfArticles);

    int totalPagesNo = (totalNoOfArticles + articlesPerPageNo - 1) / articlesPerPageNo;
    ViewData["PageTotal"] = totalPagesNo;
    ViewData["PageNo"] = pageNo;

    return View("CategoryPosts",listOfPostforCategory);
}
请注意,参数已正确传递给调试中测试的操作

有人知道这种行为的根源是什么以及如何解决吗

谢谢你的帮助。 致意

<link href="../../Content/style.css" rel="stylesheet" type="text/css" />
以下是我对_layout.cshtml图像声明的疑问

<img src="../../Content/img02.jpg" width="1000" height="300" alt="" />
当使用这种链接时 http://localhost:3282/Home/GetArticleListForCategory/1 指向其中一幅图像的链接如下所示http://localhost:3282/Content/img02.jpg 但当我向link添加一个参数时: http://localhost:3282/Home/GetArticleListForCategory/1/1 其中第一个数字是类别,第二个是页码,当链接到同一个图像时,看起来是这样的http://localhost:3282/Home/Content/img02.jpg


为什么相同的操作返回视图位于其他位置?

我认为您不需要此参数:id=UrlParameter。在您的第一个路由中是可选的。我已经检查了您的建议,但仍然是相同的行为。每个URL从GetListofShorticles返回了多少帖子?您可以发布如何在页面中包含样式表和图像吗?当您请求具有相对位置的第/1页时,它可能会起作用,但第/1/1页不会起作用,因为相对../styles/something.css必须是.././styles/something.css,在这种情况下,您需要使用Url.Content html帮助程序。如何确定返回了多少篇文章?问题在于从内容文件夹获取图像,如何在cshtml目标中指向内容文件夹的非相对路径?