Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC4控制器_C#_Asp.net Mvc_Asp.net Mvc 4_Controller - Fatal编程技术网

C# MVC4控制器

C# MVC4控制器,c#,asp.net-mvc,asp.net-mvc-4,controller,C#,Asp.net Mvc,Asp.net Mvc 4,Controller,我试图在这里创建一个双视图状态,首先我创建一个bool,检查用户是否经过身份验证,然后如果是,它会将我发送到一个视图,如果不是,它会将我发送到另一个视图。 问题是我遇到了以下错误: 传递到字典中的模型项的类型为 “System.Web.Mvc.ViewResult”,但此字典需要一个模型项 类型为NonViolenceProject.Models.ViewModels.PageViewModel`1[NonViolenceProject.Models.Pages.EducationPage]'

我试图在这里创建一个双视图状态,首先我创建一个bool,检查用户是否经过身份验证,然后如果是,它会将我发送到一个视图,如果不是,它会将我发送到另一个视图。 问题是我遇到了以下错误:

传递到字典中的模型项的类型为 “System.Web.Mvc.ViewResult”,但此字典需要一个模型项 类型为NonViolenceProject.Models.ViewModels.PageViewModel`1[NonViolenceProject.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);
    }
}
公共类教育PageController:PageController{
private bool isUserLoggedin=true;
公共行动结果索引(教育页面当前页面){
PageViewModel model=PageViewModel.Create(当前页面);
if(isUserLoggedin){
返回视图(IndexIsAuthenticated(currentPage));
}
返回视图(模型);
}
公共操作结果索引已验证(教育页面当前页面{
//isUserLoggedin=User.Identity.IsAuthenticated;
PageViewModel modelIsAuthenticated=PageViewModel.Create(currentPage);
返回视图(模型已验证);
}
}
更改

    PageViewModel<EducationPage> model = PageViewModel.Create(currentPage);
    if (isUserLoggedin)
    {
        return View(IndexIsAuthenticated(currentPage));
    }
PageViewModel=PageViewModel.Create(当前页面);
if(isUserLoggedin)
{
返回视图(IndexIsAuthenticated(currentPage));
}

PageViewModel=PageViewModel.Create(当前页面);
if(isUserLoggedin)
{
返回重定向到操作(“IndexIsAuthenticated”,模型);
}
我想这行

return View(IndexIsAuthenticated(currentPage));
应该是

return IndexIsAuthenticated(currentPage);

嗯,尝试调试这个,但我现在得到空值。不知怎的,它dsnt进入我的索引,并使用您的代码进行身份验证:/
return IndexIsAuthenticated(currentPage);