ViewEngineResult IViewEngine.FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { //Debug.WriteLine("FindPartialView: partialViewName={0}, useCache={1}", partialViewName, useCache); var namesToSearch = new List <string>(); var extension = System.IO.Path.GetExtension(partialViewName); if (string.IsNullOrEmpty(extension)) { namesToSearch.Add(partialViewName + ".cshtml"); namesToSearch.Add(partialViewName + ".vbhtml"); } else { namesToSearch.Add(partialViewName); } foreach (var _partialViewName in namesToSearch) { var partialViewNamePath = GetFilePath(GetModuleNameFromContext(controllerContext), _partialViewName, true, out IEnumerable <string> searchLocations); if (!string.IsNullOrEmpty(partialViewNamePath)) { var res = new ViewEngineResult(CreatePartialView(controllerContext, partialViewNamePath), this); return(res); } } return(_previousViewEngine.FindPartialView(controllerContext, partialViewName, useCache)); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { var engineResult = _engine.FindPartialView(controllerContext, partialViewName, useCache); InterceptEngineResult(engineResult); return(engineResult); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { var result = inner.FindPartialView(controllerContext, partialViewName, useCache); AppendRazorViewPath(controllerContext, result); return(result); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { var result = _innerViewEngine.FindPartialView(controllerContext, partialViewName, useCache); return(CreateTracingViewEngineResult(result, partialViewName)); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindPartialView, {1}, {2}", _name, partialViewName, useCache))) { return(WrapResult(_inner.FindPartialView(controllerContext, partialViewName, useCache))); } }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { partialViewName = RazorCompressHelper.GetCompressedViewName(controllerContext, partialViewName); var result = _razorViewEngine.FindPartialView(controllerContext, partialViewName, useCache); return(result); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { if (IsAllowed(controllerContext)) { return(inner.FindPartialView(controllerContext, partialViewName, useCache)); } return(new ViewEngineResult(Enumerable.Empty <string>())); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { var found = wrapped.FindPartialView(controllerContext, partialViewName, useCache); if (found != null && found.View != null) { found = new ViewEngineResult(new WrappedView(found.View, partialViewName, isPartial: true), this); } return(found); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { IViewEngine viewEngine = GetViewEngine(controllerContext); if (viewEngine != null) { return(viewEngine.FindPartialView(controllerContext, partialViewName, useCache)); } return(new ViewEngineResult(new string[0])); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { var result = baseViewEngine.FindPartialView(controllerContext, partialViewName, useCache); if (result.View != null) { return(new ViewEngineResult(new RazorXView(result.View), this)); } return(result); }
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { if (_predicate(controllerContext)) { var result = _innerViewEngine.FindPartialView(controllerContext, _viewNameProvider(partialViewName), useCache); if (result != null && result.View != null) { return(result); } } return(new ViewEngineResult(new string[] { })); }
private IView FindView(ActionContext context, string viewName) { var result = _viewEngine.FindPartialView(context, viewName); if (!result.Success) { var locations = string.Empty; if (result.SearchedLocations != null) { locations = Environment.NewLine + string.Join(Environment.NewLine, result.SearchedLocations); } throw new InvalidOperationException(Resources.FormatViewEngine_ViewNotFound(viewName, locations)); } return(result.View); }
public void AjaxGrid_RendersAjaxGridPartial() { IView view = Substitute.For <IView>(); IViewEngine engine = Substitute.For <IViewEngine>(); ViewEngineResult result = Substitute.For <ViewEngineResult>(view, engine); engine.FindPartialView(Arg.Any <ControllerContext>(), "MvcGrid/_AjaxGrid", Arg.Any <Boolean>()).Returns(result); view.When(sub => sub.Render(Arg.Any <ViewContext>(), Arg.Any <TextWriter>())).Do(sub => { Assert.Equal("DataSource", sub.Arg <ViewContext>().ViewData.Model); sub.Arg <TextWriter>().Write("Rendered"); }); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(engine); String actual = html.AjaxGrid("DataSource").ToHtmlString(); String expected = "Rendered"; Assert.Equal(expected, actual); }
public void ToHtmlString_RendersPartialView() { IView view = Substitute.For <IView>(); IViewEngine engine = Substitute.For <IViewEngine>(); ViewEngineResult result = Substitute.For <ViewEngineResult>(view, engine); engine.FindPartialView(Arg.Any <ControllerContext>(), htmlGrid.PartialViewName, Arg.Any <Boolean>()).Returns(result); view.When(sub => sub.Render(Arg.Any <ViewContext>(), Arg.Any <TextWriter>())).Do(sub => { Assert.AreEqual(htmlGrid.Grid, sub.Arg <ViewContext>().ViewData.Model); sub.Arg <TextWriter>().Write("Rendered"); }); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(engine); String actual = htmlGrid.ToHtmlString(); String expected = "Rendered"; Assert.AreEqual(expected, actual); }
public string Render() { var defaultActions = GetDefaultActions(); var modeViewPath = _readOnly ? DisplayTemplateViewPath : EditorTemplateViewPath; foreach (string viewName in GetViewNames()) { var fullViewName = modeViewPath + "/" + viewName; var viewEngineResult = _viewEngine.FindPartialView(_viewContext, fullViewName); if (viewEngineResult.Success) { using (var writer = new StringWriter(CultureInfo.InvariantCulture)) { // Forcing synchronous behavior so users don't have to await templates. // TODO: Pass through TempData once implemented. var view = viewEngineResult.View; using (view as IDisposable) { var viewContext = new ViewContext(_viewContext, viewEngineResult.View, _viewData, writer); var renderTask = viewEngineResult.View.RenderAsync(viewContext); TaskHelper.WaitAndThrowIfFaulted(renderTask); return(writer.ToString()); } } } Func <IHtmlHelper, string> defaultAction; if (defaultActions.TryGetValue(viewName, out defaultAction)) { return(defaultAction(MakeHtmlHelper(_viewContext, _viewData))); } } throw new InvalidOperationException( Resources.FormatTemplateHelpers_NoTemplate(_viewData.ModelMetadata.RealModelType.FullName)); }
public IHtmlContent Render() { var defaultActions = GetDefaultActions(); var modeViewPath = _readOnly ? DisplayTemplateViewPath : EditorTemplateViewPath; foreach (string viewName in GetViewNames()) { var fullViewName = modeViewPath + "/" + viewName; var viewEngineResult = _viewEngine.FindPartialView(_viewContext, fullViewName); if (viewEngineResult.Success) { using (var writer = new StringCollectionTextWriter(_viewContext.Writer.Encoding)) { // Forcing synchronous behavior so users don't have to await templates. var view = viewEngineResult.View; using (view as IDisposable) { var viewContext = new ViewContext(_viewContext, viewEngineResult.View, _viewData, writer); var renderTask = viewEngineResult.View.RenderAsync(viewContext); renderTask.GetAwaiter().GetResult(); return(writer.Content); } } } Func <IHtmlHelper, IHtmlContent> defaultAction; if (defaultActions.TryGetValue(viewName, out defaultAction)) { return(defaultAction(MakeHtmlHelper(_viewContext, _viewData))); } } throw new InvalidOperationException( Resources.FormatTemplateHelpers_NoTemplate(_viewData.ModelExplorer.ModelType.FullName)); }
/// <inheritdoc /> protected override ViewEngineResult FindView([NotNull] IViewEngine viewEngine, [NotNull] ActionContext context, [NotNull] string viewName) { return(viewEngine.FindPartialView(context, viewName)); }
/// <summary> /// Finds a view for the given name. /// </summary> /// <param name="context">The action context.</param> /// <param name="viewEngine">The view engine.</param> /// <param name="viewName">The view name.</param> /// <returns>The resolved view instance.</returns> private static IView FindView(ActionContext context, IViewEngine viewEngine, string viewName) { return viewEngine.FindPartialView(context, viewName).EnsureSuccessful().View; }
/// <summary> /// Find a partial view /// </summary> /// <param name="controllerContext">The context to search for this partial with.</param> /// <param name="partialViewName">The view name to search for.</param> /// <param name="useCache">Whether to use cached lookups.</param> public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) => Find(partialViewName, () => _wrapped.FindPartialView(controllerContext, partialViewName, useCache), isPartial: true);
public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { return(_innerViewEngine.FindPartialView(controllerContext, partialViewName, useCache)); }
private static IView FindView(ActionContext context, IViewEngine viewEngine, string viewName) { return(viewEngine.FindPartialView(context, viewName).EnsureSuccessful().View); }
/// <summary> /// Find a partial /// </summary> public ViewEngineResult FindPartialView(ControllerContext ctx, string partialViewName, bool useCache) { return(Find(ctx, partialViewName, () => _wrapped.FindPartialView(ctx, partialViewName, useCache), isPartial: true)); }
public virtual ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache) { return(_wrappedEngine.FindPartialView(controllerContext, partialViewName, useCache)); }