我使用虚拟路径提供程序将我的视图存储在数据库中。我遇到的问题是,每当我从我的数据库更改视图代码时,我的渲染代码总是生成应用程序启动时保存的视图。所以我现在的问题是我必须不断重新启动我的应用程序才能改变我的观点。这是我的渲染代码:
public static string RenderRazorViewToString(string viewToRender, object model, string controllerName, string loadAction, HttpContextBase httpContext)
{
string view = "";
ViewDataDictionary ViewData = new ViewDataDictionary(model);
Type controllerType = Type.GetType("CMS.Controllers." + controllerName + "Controller");
object controller = Activator.CreateInstance(controllerType);
RouteData rd = new System.Web.Routing.RouteData();
rd.Values.Add("controller", controllerName);
((ControllerBase)(controller)).ControllerContext = new ControllerContext(httpContext, rd, (ControllerBase)controller);
ControllerContext cc = ((ControllerBase)(controller)).ControllerContext;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(cc, viewToRender);
var viewContext = new ViewContext(cc, viewResult.View, ViewData, cc.Controller.TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(cc, viewResult.View);
view = sw.GetStringBuilder().ToString();
}
return view;
}
ViewResult.View.Render(viewContext, sw)
始终呈现缓存的视图。那么每当我编辑视图代码时如何删除缓存?