レイアウトページにボタンがあり、異なるビュー間を移動することになっています。
<a id="next" href="/Navigation?CurrentPage=@ViewBag.CurrentPage">Next</a>
ViewBag.CurrentPage
各ページの ViewModel に値を入力します。
ナビゲーション コントローラーは、次のコントローラーでアンカー クリックをインターセプトします -
public class NavigationController : Controller
{
public void Index(string CurrentPage)
{
PageType currentPageEnum = (PageType)Enum.Parse(typeof(PageType), CurrentPage);
PageType nextPageEnum = currentPageEnum + 1;
RedirectToAction(nextPageEnum.ToString());
}
}
Enum には ActionNames が順番に含まれているため、 currentPageEnum 値をインクリメントして次のページを見つけます。
enum PageType
{
Page1,
Page2
}
各アクションには、次のように Global.asax.cs にマッピング ルートがあります。
routes.MapRoute("Page1", "Page1", new { controller="controller1", action="Page1"});
routes.MapRoute("Page2", "Page2", new { controller="controller2", action="Page2"});
質問: このコードで他のコントローラーにリダイレクトできませんでした-
RedirectToAction(nextPageEnum.ToString());
リクエストはリダイレクトなしで終了します。
- どのような情報が不足していますか。
- ASP MVC で、異なるビュー間を移動するより効率的な方法はありますか
ありがとう!