MVC错误页面没有显示,如何修复?

时间:2015-03-09 16:54:28

标签: c# asp.net-mvc

我在web.config中有这一行:

    <customErrors mode="On" defaultRedirect="~/Error" redirectMode="ResponseRedirect"/>

错误命中error.cshtml页面并从错误页面发送错误电子邮件,但error.cshtml页面不会在屏幕上呈现,它会保留在当前页面上。

以下是控制器中导致错误的代码。我知道如何解决这个错误,我故意试图让error.cshtml页面显示出来。

            public ViewResult UpdateCountySessionVariables(string countyId)
    {
        //was viewresult

        CountyModel countyModel = new CountyModel();
        countyModel = _countyRepo.GetCounty(Int32.Parse(countyId));
        Session["CountyName"] = countyModel.Name;
        Session["CountyId"] = countyId;

        int newCountyId = Int32.Parse(Session["CountyId"].ToString());
        int currentFiscalYearId = Int32.Parse(Session["CurrentFiscalYearId"].ToString());

        ModelState.Clear();
        AnnualReportModel annualReportModel = _annualReportRepo.GetAnnualReport(newCountyId, currentFiscalYearId);
        AnnualReportViewModel annualReportViewModel = new AnnualReportViewModel();
                    annualReportViewModel.AnnualReportModel = _annualReportRepo.GetAnnualReport(annualReportModel.Id);

            string fiscalYearStartYear = annualReportViewModel.AnnualReportModel.FiscalYearModel.Name.Substring(0, 4);
            string fiscalYearEndYear = annualReportViewModel.AnnualReportModel.FiscalYearModel.Name.Substring(5, 4);

            annualReportViewModel.fiscalYearStartYear = fiscalYearStartYear;
            annualReportViewModel.fiscalYearEndYear = fiscalYearEndYear;
            annualReportViewModel.Counties = _countyRepo.GetCounties();

            var CountyName = Session["CountyName"].ToString();

        return View("Index", annualReportViewModel);

    }

我该如何解决?

0 个答案:

没有答案