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

我猜这条线

return View(IndexIsAuthenticated(currentPage));

应该

return IndexIsAuthenticated(currentPage);
于 2013-09-10T12:55:08.797 回答
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 回答