前台html:
<form action="/ContractManagement/ContractTermsExcerpt" method="post">
<input name="contractNO" class="contractNO" type="text">
<input type="submit" formtarget="_blank" value="合同条款摘录" />
</form>
后台控制器:
public ActionResult ContractTermsExcerpt(string contractNO)
{
var result = from c in db.ConditionsContracts.Where(b => b.contractNO == contractNO) select c;
return View(JsonSerializeHelper.SerializeToJson(result.ToList()));
}
显示页面提示的错误是:
“/”应用程序中的服务器错误。
未找到视图“[]”或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置:
~/Views/ContractManagement/[].aspx
~/Views/ContractManagement/[].ascx
~/Views/Shared/[].aspx
~/Views/Shared/[].ascx
~/Views/ContractManagement/[].cshtml
~/Views/ContractManagement/[].vbhtml
~/Views/Shared/[].cshtml
~/Views/Shared/[].vbhtml
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: 未找到视图“[]”或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置:
~/Views/ContractManagement/[].aspx
~/Views/ContractManagement/[].ascx
~/Views/Shared/[].aspx
~/Views/Shared/[].ascx
~/Views/ContractManagement/[].cshtml
~/Views/ContractManagement/[].vbhtml
~/Views/Shared/[].cshtml
~/Views/Shared/[].vbhtml
是return View(JsonSerializeHelper.SerializeToJson(result.ToList()));
这行代码引起的,JsonSerializeHelper.SerializeToJson(result.ToList())
的结果被当作了视图名称。
解决方法:
return View("ContractTermsExcerpt", JsonSerializeHelper.SerializeToJson(result.ToList()));
路由未匹配上导致查找不到视图
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "UserLogin", id = UrlParameter.Optional }
);
}
我还是没找到原因!上面是我的路由器配制代码!请指点,谢谢!