Asp.net mvc 视图';主页';或者找不到其主节点,或者没有视图引擎支持搜索的位置。搜索了以下地点:';零星错误';

Asp.net mvc 视图';主页';或者找不到其主节点,或者没有视图引擎支持搜索的位置。搜索了以下地点:';零星错误';,asp.net-mvc,view,asp.net-mvc-routing,viewengine,Asp.net Mvc,View,Asp.net Mvc Routing,Viewengine,在尝试返回视图时,使用MVC4应用程序时会出现零星错误 在本例中,我将返回一个视图返回视图(“Home”,model)这就是我得到消息的地方。当您不断地进行测试和调试时,它似乎也偶尔发生,我认为视图引擎变得疯狂。例如,在这之前,我正在执行一个简单的视图,并说当它一直在那里时,它找不到它。在清除缓存、重新启动等并执行相同的精确逻辑之后,它工作了 所以,我不知道如何用视图引擎解决这个问题。在我回到视图之前,我可以向您保证,我的模型中有记录。我无法从我的电脑将屏幕打印附加到此表单上--没有选项 所以,

在尝试返回视图时,使用MVC4应用程序时会出现零星错误

在本例中,我将返回一个视图
返回视图(“Home”,model)这就是我得到消息的地方。当您不断地进行测试和调试时,它似乎也偶尔发生,我认为视图引擎变得疯狂。例如,在这之前,我正在执行一个简单的视图,并说当它一直在那里时,它找不到它。在清除缓存、重新启动等并执行相同的精确逻辑之后,它工作了

所以,我不知道如何用视图引擎解决这个问题。在我回到视图之前,我可以向您保证,我的模型中有记录。我无法从我的电脑将屏幕打印附加到此表单上--没有选项

所以,可怕的问题是:我如何解决这个问题,而不是像这样偶尔发生???这是一个严重的问题,希望能得到解决

我看了ScottHanselmansNuget包的预编译视图等,但似乎过于复杂,需要额外的工作。我想知道我还能做些什么

任何帮助都将不胜感激

这是我的Globla.asax文件:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}
如果有人能回答,我将不胜感激,因为这将使我们正在开发的MVC应用程序停止运行

我尝试添加
.DataTokens.Add(“area”,“yourrealename”)
放在
映射路径的末尾,但我不知道用什么替换字符串

此外,我不知道为什么需要这样做(如果它能解决它的话)并且需要某人的解释

为想要签出控制器代码的另一个人添加了代码

[HttpPost]
        public ActionResult Refresh(ViewModelTemplate_Guarantors model)
        {
            try
            {
                model.Error = string.Empty;

                bool dbHasRows = db.ChkLoanFields(Convert.ToInt32(model.LoanId));

                if (!dbHasRows)
                {
                    ViewBag.ShowTemps = false;
                    model.Error = "Details not available for this LoanId.";
                    return View("Home", model);
                }
                else
                {
                    int TemplateCnt = 0;
                    int GuarantorCnt = 0;
                    ViewBag.ShowTemps = true;

                    ViewModelTemplate_Guarantors tg = db.SelectViewModelTemplate_Guarantors(Convert.ToInt32(model.LoanId), "1", model.SelectedDeptText, out TemplateCnt, out GuarantorCnt);

                    if (TemplateCnt > 0)
                        model.Templates = tg.Templates;
                    else 
                       model.ErrorT = "Templates not available for this LoanType.";

                    if (GuarantorCnt > 0)
                        model.Guarantors = tg.Guarantors;
                    else
                        model.ErrorG = "Guarantors not available for this LoanId.";

                    return View("Home", model);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
我不明白为什么路由引擎在我的目录结构清楚显示时会尝试执行以下操作: Views/Home/Index.cshtml

下面是givien的错误,甚至没有查找“索引”页面

替换此项:

return View("Home", model);
为此:

return View("Index", model);
完整代码:

public ActionResult Refresh(ViewModelTemplate_Guarantors model)
{
    try
    {
        model.Error = string.Empty;

        bool dbHasRows = db.ChkLoanFields(Convert.ToInt32(model.LoanId));

        if (!dbHasRows)
        {
            ViewBag.ShowTemps = false;
            model.Error = "Details not available for this LoanId.";
            return View("Home", model);
        }
        else
        {
            int TemplateCnt = 0;
            int GuarantorCnt = 0;
            ViewBag.ShowTemps = true;

            ViewModelTemplate_Guarantors tg = db.SelectViewModelTemplate_Guarantors(Convert.ToInt32(model.LoanId), "1", model.SelectedDeptText, out TemplateCnt, out GuarantorCnt);

            if (TemplateCnt > 0)
                model.Templates = tg.Templates;
            else
                model.ErrorT = "Templates not available for this LoanType.";

            if (GuarantorCnt > 0)
                model.Guarantors = tg.Guarantors;
            else
                model.ErrorG = "Guarantors not available for this LoanId.";

            return View("Index", model);
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

您是否可以在调用返回视图(“主页”,型号)的地方包含控制器代码?我的代码包含在编辑的底部。。如果有其他地方我应该把编辑添加,请告诉我。让我知道如果你没有看到编辑(在我的文章底部)尽快。因为我刚把它贴出来。。。非常感谢您查看它…必须有一种方法在项目中以某种方式修复此问题,并告知它默认视图是什么。您可以清楚地看到它导致错误的原因,但我不知道为什么…消息正在寻找“主页”作为Global.asax文件中的操作方法,它明确指定了以下内容:如何更正:routes.maprote(名称:“Default”,url:“{controller}/{action}/{id}”,默认值:new{controller=“Home”,action=“Index”,id=UrlParameter.Optional});
public ActionResult Refresh(ViewModelTemplate_Guarantors model)
{
    try
    {
        model.Error = string.Empty;

        bool dbHasRows = db.ChkLoanFields(Convert.ToInt32(model.LoanId));

        if (!dbHasRows)
        {
            ViewBag.ShowTemps = false;
            model.Error = "Details not available for this LoanId.";
            return View("Home", model);
        }
        else
        {
            int TemplateCnt = 0;
            int GuarantorCnt = 0;
            ViewBag.ShowTemps = true;

            ViewModelTemplate_Guarantors tg = db.SelectViewModelTemplate_Guarantors(Convert.ToInt32(model.LoanId), "1", model.SelectedDeptText, out TemplateCnt, out GuarantorCnt);

            if (TemplateCnt > 0)
                model.Templates = tg.Templates;
            else
                model.ErrorT = "Templates not available for this LoanType.";

            if (GuarantorCnt > 0)
                model.Guarantors = tg.Guarantors;
            else
                model.ErrorG = "Guarantors not available for this LoanId.";

            return View("Index", model);
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}