无法将类型为“System.Web.Mvc.ViewResult”的对象强制转换为“System.Web.Mvc.PartialViewResult”

时间:2016-05-26 16:54:46

标签: asp.net asp.net-mvc razor child-actions

我有Html.Action方法我的layout.cshtml文件,每个页面上的rander搜索表单。在布局文件中,我有这种情况呈现:

@if (dcmodel != null)
{
    @Html.Action("SearchForm", "Document", dcmodel)
}
else
{
    @Html.Action("SearchForm", "Document")
}

在文档控制器中,我有以下代码:

[ChildActionOnly]
public ActionResult SearchForm()
{
    DocumentSearchModel model = (DocumentSearchModel)TempData["SearchForm"];

    var documentSearchModel = new DocumentSearchModel();

    if (model != null)
    {
        documentSearchModel = model;
    }

    AccessRight accessRight = unitOfWork.PermissionRepository.GetBOPermission(ApplicationViewRight.Document);
    documentSearchModel.ViewModelPermission = new ViewModelPermission(accessRight);

    documentSearchModel.DocumentStatuses = CreateDocumentStatusSelectList();
    documentSearchModel.DocumentTypes = CreateDocumentTypeSelectList();
    documentSearchModel.Storages = CreateStoragesSelectList();

    AccessRight documentAccessRight = unitOfWork.PermissionRepository.GetBOPermission(ApplicationViewRight.ShreddingManagement);

    documentSearchModel.IsShreddingAvailable = documentAccessRight.HasFlag(AccessRight.Create);
    documentSearchModel.IsUserSupervisor = unitOfWork.UserRepository.IsUserSupervisor();

    documentSearchModel.ShowLuceneSearch = unitOfWork.SystemSettingRepository.GetSettingsByCode("UseLuceneSearch").Value.ToLower() == "true";

    return PartialView("_SearchForm", documentSearchModel);
}

    [HttpPost]
    public ActionResult SearchForm(DocumentSearchModel searchModel)
    {

        var dataRequest = this.HttpContext.Request;

        Stream req = Request.InputStream;
        req.Seek(0, System.IO.SeekOrigin.Begin);
        string json = new StreamReader(req).ReadToEnd();

        var input = JsonConvert.DeserializeObject(json);

        TempData["SearchFormJson"] = input;

        TempData["SearchForm"] = searchModel;
        return RedirectToAction("Index");
    }

当我登录页面时,每个方面都在工作......当我更改本地时间+2小时并刷新页面时,我在下面收到此错误。

我做错了什么?请帮忙! Thnaks!

  

无法将“System.Web.Mvc.ViewResult”类型的对象强制转换为“System.Web.Mvc.PartialViewResult”

     

位于C:\ Projects \ TT \ Controllers \ DocumentController.cs中的TT.MVCClient.Controllers.DocumentController.SearchForm():第138行          在lambda_method(Closure,ControllerBase,Object [])          在System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []参数)          在System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary`2参数)          在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2参数)          在System.Web.Mvc.ControllerActionInvoker。<> c__DisplayClass13.b__10()          在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter过滤器,ActionExecutingContext preContext,Func`1 continuation)

     

{“执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'的子请求时出错。”}

0 个答案:

没有答案