2012-04-03 9 views
0

ロジックを正しく取得できません。私は、コントローラ内の別々のビュー(javascriptなし)を持つウィザードを使用しています。ウィザードのステップ2の選択に基づいて、ステップ7をスキップするか、またはステップ7を表示します。ウィザードは、次/戻るボタンを使用してどこを移動するかを制御します。(ウィザードを使用して)前のビューでの選択に基づいてビューを表示/スキップするコントローラロジック

ユーザーが「A」(たとえば)を選択した場合はステップ7を表示できましたが、「B」または「C」のいずれかを選択した場合はステップ7をスキップするロジックを作成したときに、 Chrome上で「リダイレクトループ/リダイレクトエラーが多すぎます」(クッキーを使用不可にする)または前の手順で「次へ」ボタンは機能しません(同じビューが表示されます)。

ステップ2はコントローラの点では重要ではありません.3つの選択肢を持つドロップダウンリストがあり、その選択肢に基づいてこれは私が持っているコントローラコードです(myViewModelコードを[Serializable]で飾られているコントローラ、):

// STEP 6: 
    // Based on selection in Step 2, show or don't show Step 7 
    public ActionResult Step6(string backButton, string nextButton) 
    { 
     if (backButton != null) 
      return RedirectToAction("Step5"); 
     else if ((nextButton != null) && 
      ModelState.IsValid && 
      (myVieModel.MyModel.MyDropDown == 
      MyNamespace.Models.MyModel.MyEnum.A)) 
      return RedirectToAction("Step7"); 
     else if ((nextButton != null) && 
      ModelState.IsValid && 
      (myVieModel.MyModel.MyDropDown == 
      MyNamespace.Models.MyModel.MyEnum.B) || 
      (myVieModel.MyModel.MyDropDown == 
      MyNamespace.Models.MyModel.MyEnum.C)) 
      return RedirectToAction("Step8"); 
     else 
      return View("Step6", myViewModel); 
    } 

    // STEP 7: 
    // Only shown if Choice in MyDropDown is "A", 
    // otherwise if "B" or "C" skipped 
    public ActionResult Step7(string backButton, string nextButton) 
    { 
     if (backButton != null) 
      return RedirectToAction("Step6"); 
     else if ((nextButton != null) && 
      ModelState.IsValid) 
      return RedirectToAction("Step8"); 
     else 
      return View("Step7", myViewModel); 
    } 

    // STEP 8: 
    // Arrive here either from Step 6 
    // (if "B" or "C" chosen), 
    // or from Step 7 (if "A" chosen) 
    public ActionResult Step8(string backButton, string nextButton) 
    { 
     if ((backButton != null) && 
      (myVieModel.MyModel.MyDropDown == 
      MyNamespace.Models.MyModel.MyEnum.A)) 
      return RedirectToAction("Step7"); 
     else if ((backButton != null) && 
      (myVieModel.MyModel.MyDropDown == 
      MyNamespace.Models.MyModel.MyEnum.B) || 
      (myVieModel.MyModel.MyDropDown == 
      MyNamespace.Models.MyModel.MyEnum.C)) 
      return RedirectToAction("Step6"); 
     else if ((nextButton != null) && 
      ModelState.IsValid) 
      return RedirectToAction("Step9"); 
     else 
      return View("Step8", myViewModel); 
    } 

私はちょうどダウン間違ったロジックを取得しています知っています。どんな助けでも大歓迎です。

上記のコード(私が求めているロジックなし)は、DropDownを表示するために使用するコードと同様に、完全に機能します。

答えて

0

うわ、私はthusly読み取るために、独自の()||ロジックをカプセル化しておく必要があります。

else if ((backButton != null) && 
    //Extra opening parenthesis--> 
    ((myVieModel.MyModel.MyDropDown == 
    MyNamespace.Models.MyModel.MyEnum.B) || 
    (myVieModel.MyModel.MyDropDown == 
    MyNamespace.Models.MyModel.MyEnum.C))) //<--extra closing parenthesis 
    return RedirectToAction("Step6"); 
+0

誰もがよりよい解決策を持っている場合は、単にそれを投稿して、私は、2日間の私自身の答えを受け入れることはできません。 – REMESQ

関連する問題