1

ここで二重のビュー状態を作成しようとしています。まず、ユーザーが認証されているかどうかを確認するブール値を作成し、認証されている場合はビューに送信し、認証されていない場合は別のビューに送信します。問題は、次のエラーが発生することです。

ディクショナリに渡されたモデル アイテムのタイプは「System.Web.Mvc.ViewResult」ですが、このディクショナリにはタイプ TheNonViolenceProject.Models.ViewModels.PageViewModel`1[TheNonViolenceProject.Models.Pages.EducationPage]' のモデル アイテムが必要です。

これが私のコードです:

public class EducationPageController : PageController<EducationPage> {
    private bool isUserLoggedin = true;

    public ActionResult Index(EducationPage currentPage) {
        PageViewModel<EducationPage> model = PageViewModel.Create(currentPage);
        if (isUserLoggedin) {
            return View(IndexIsAuthenticated(currentPage));
        }
        return View(model);
    }

    public ActionResult IndexIsAuthenticated(EducationPage currentPage {
        //isUserLoggedin = User.Identity.IsAuthenticated;
        PageViewModel<EducationPage> modelIsAuthenticated = PageViewModel.Create(currentPage);
        return View(modelIsAuthenticated);
    }
}
4

2 に答える 2

0

変化する

    PageViewModel<EducationPage> model = PageViewModel.Create(currentPage);
    if (isUserLoggedin)
    {
        return View(IndexIsAuthenticated(currentPage));
    }

    PageViewModel<EducationPage> model = PageViewModel.Create(currentPage);
    if (isUserLoggedin)
    {
        return RedirectToAction("IndexIsAuthenticated", model);
    }
于 2013-09-10T11:53:56.563 に答える
0

推しはこのライン

return View(IndexIsAuthenticated(currentPage));

する必要があります

return IndexIsAuthenticated(currentPage);
于 2013-09-10T12:55:08.797 に答える