一、定义:
Control (HomeControler)
public class HomeController : BaseController
{
public ActionResult Head()
{
ViewBag.Name = "armHead";
return PartialView("Head");
}
}
View (Head.cshtml)
@*这里是“Head”Partial View*@
@ViewBag.Name
二、使用:
View
<!DOCTYPE html>
<html>
<head>
</head>
<body>
这里是普通视图
@Html.Action("Head","Home")
</body>
</html>
环境:MVC3+Razor+.NET(C#)
异常收集:
Duration must be a positive number.
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: Duration must be a positive number.
源错误:
行 81: </head>
行 82: <body class="bodyIndex">
行 83: @Html.Action("Header","Partials")
行 84: <div class="banner">
行 85: <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="964" height="360"> |
源文件: d:\NETproject\SDJT\SDJT\XJ.SDJT.Web\Views\Home\Index.cshtml 行: 83
由于Controller中添加了[OutputCache(Duration = 0, VaryByParam = "none")]导致的错误
Duration 设置为正整数解决。
[OutputCache(Duration = 1, VaryByParam = "none")]
public ActionResult Header()
{
var user = LoadService<IMemberService>().GetFilteredElement(u => u.PKID == CurrentUserID);
if (user != null)
{
ViewBag.UserName = user.UserName;
}
return PartialView("Header");
}