1

我正在编写简单的网页(一种博客),但因以下问题而被阻止。在 _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);
}

请注意,参数已正确传递给操作(在调试中测试)。

有谁知道这种行为的根源是什么以及如何解决它?

提前感谢您的帮助。此致

4

1 回答 1

0
<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 但是当我向链接添加另一个参数时: http://localhost:3282/Home/GetArticleListForCategory/1/1 其中第一个数字是类别,第二个是页码,同一图像的链接看起来像http://localhost:3282/Home/Content/img02.jpg

为什么相同的动作返回视图位于其他地方?

于 2013-01-15T18:51:15.600 回答