我正在编写简单的网页(一种博客),但因以下问题而被阻止。在 _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);
}
请注意,参数已正确传递给操作(在调试中测试)。
有谁知道这种行为的根源是什么以及如何解决它?
提前感谢您的帮助。此致