1

私は単純な Web ページ (一種のブログ) を書いていますが、次の問題でブロックされています。Views/Shared in _Layout.cshtml で、ページのレイアウトを定義しました。

私のルーティングルールは次のようになります

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からアクションを実行すると 、ページは「未加工」に見えます(ページにレイアウトや画像などはありません)。2 つのリンクからページによって返される 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 画像の1つへのリンクはhttp:// localhost:3282 / Content / img02.jpg のようになりますが、リンクにもう1つのパラメーターを追加すると次のようになります。 http:// localhost:3282 / Home / GetArticleListForCategory / 1/1 ここで、最初の番号はカテゴリ、2番目の番号はページ番号で、同じ画像へのリンクは次のようになりますhttp:// localhost:3282 / Home / Content / img02.jpg

なぜ同じアクションが他の場所にあるビューを返すのですか?

于 2013-01-15T18:51:15.600 に答える