sag*_*y36 2 asp.net-mvc view asp.net-mvc-routing viewengine
在尝试返回View时,使用我的MVC 4应用程序时出现偶发错误.
在这种特殊情况下,我即将返回一个View return View("Home", model);,这就是我获取msg的地方.当您不断进行测试和调试时,它似乎偶尔也会发生,我认为View Engine会疯狂.例如,在此之前,我正在执行一个简单的视图,并说当它一直存在时无法找到它.结合清除缓存,重新启动等,并执行相同的确切逻辑后,它工作.
所以,我不知道如何使用View Engine解决这个问题.在我回到View之前,我可以向你保证我的模型中有记录.我不能在我的电脑上附上这张表格上的丝网印刷品 - 没有选择.
所以,可怕的问题是:如何解决这个问题,它不会偶尔发生这样的问题?这是一个严重的问题,希望能够解决这个问题....
我查看了Scott Hanselmans nuget包的预编译视图等,但似乎过于复杂和额外的工作.我想知道我能做些什么.
任何帮助将非常感激....
这是我的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 }
);
}
Run Code Online (Sandbox Code Playgroud)
如果有人可以请回答,我将不胜感激,因为这将使我们正在努力的MVC应用程序停止!
我尝试添加.DataTokens.Add("area", "YOURAREANAME");到最后MapRoute,但我不知道用什么来代替字符串.
另外,我不知道为什么要这样做(如果它会修复它)并需要某人的解释......
为另一个想要签出控制器代码的人添加了代码.
[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;
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么ROUTING引擎试图转到下面,当我的目录结构清楚时:Views/Home/Index.cshtml
givien的错误在下面,甚至没有查找"索引"页面.
~/Views/Home/Home.aspx
~/Views/Home/Home.ascx
~/Views/Shared/Home.aspx
~/Views/Shared/Home.ascx
~/Views/Home/Home.cshtml
~/Views/Home/Home.vbhtml
~/Views/Shared/Home.cshtml
~/Views/Shared/Home.vbhtml
Run Code Online (Sandbox Code Playgroud)
替换这个:
return View("Home", model);
Run Code Online (Sandbox Code Playgroud)
有了这个:
return View("Index", model);
Run Code Online (Sandbox Code Playgroud)
完整代码:
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;
}
}
Run Code Online (Sandbox Code Playgroud)