diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs index c473b3b77e..729ed5c227 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; @@ -22,14 +23,11 @@ namespace Microsoft.AspNet.Mvc public ViewData ViewData { get; set; } - public async Task ExecuteResultAsync(ActionContext context) + public async Task ExecuteResultAsync([NotNull] ActionContext context) { - if (context == null) - { - throw new ArgumentNullException("context"); - } + var viewName = ViewName ?? context.ActionDescriptor.Name; + var view = await FindView(context.RouteValues, viewName); - IView view = await FindView(context, ViewName); using (view as IDisposable) { context.HttpContext.Response.ContentType = "text/html"; @@ -44,12 +42,12 @@ namespace Microsoft.AspNet.Mvc } } - private async Task FindView(ActionContext actionContext, string viewName) + private async Task FindView([NotNull] IDictionary context,[NotNull] string viewName) { - ViewEngineResult result = await _viewEngine.FindView(actionContext, viewName); + var result = await _viewEngine.FindView(context, viewName); if (!result.Success) { - string locationsText = string.Join(Environment.NewLine, result.SearchedLocations); + var locationsText = string.Join(Environment.NewLine, result.SearchedLocations); const string message = @"The view '{0}' was not found. The following locations were searched:{1}."; throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, message, viewName, locationsText)); } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controller.cs b/src/Microsoft.AspNet.Mvc.Core/Controller.cs index a1d1a0936d..4f0a870f72 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controller.cs @@ -31,8 +31,7 @@ namespace Microsoft.AspNet.Mvc public IActionResult View(string view) { - object model = null; - return View(view, model); + return View(view, model: (object)null); } public IActionResult View(TModel model) diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs index ea19ea43ae..a70e9103eb 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs @@ -28,27 +28,8 @@ namespace Microsoft.AspNet.Mvc.Razor get { return _viewLocationFormats; } } - public async Task FindView(object context, string viewName) + public async Task FindView([NotNull] IDictionary context,[NotNull] string viewName) { - var actionContext = (ActionContext)context; - - var actionDescriptor = actionContext.ActionDescriptor; - - if (actionDescriptor == null) - { - return null; - } - - if (string.IsNullOrEmpty(viewName)) - { - viewName = actionDescriptor.Name; - } - - if (string.IsNullOrEmpty(viewName)) - { - throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, "viewName"); - } - var nameRepresentsPath = IsSpecificPath(viewName); if (nameRepresentsPath) @@ -59,8 +40,8 @@ namespace Microsoft.AspNet.Mvc.Razor } else { - var controllerName = actionContext.RouteValues.GetValueOrDefault("controller"); - var areaName = actionContext.RouteValues.GetValueOrDefault("area"); + var controllerName = context.GetValueOrDefault("controller"); + var areaName = context.GetValueOrDefault("area"); var searchedLocations = new List(_viewLocationFormats.Length); for (int i = 0; i < _viewLocationFormats.Length; i++) @@ -73,6 +54,7 @@ namespace Microsoft.AspNet.Mvc.Razor } searchedLocations.Add(path); } + return ViewEngineResult.NotFound(searchedLocations); } } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs index 1836c47795..99ba0701f3 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs @@ -83,26 +83,6 @@ namespace Microsoft.AspNet.Mvc.Rendering return value != null ? WebUtility.HtmlEncode(value.ToString()) : string.Empty; } - internal static IView FindPartialView([NotNull] ViewContext viewContext, string partialViewName, - [NotNull] IViewEngine viewEngine) - { - ViewEngineResult result = viewEngine.FindView(viewContext, partialViewName).Result; - if (result.View != null) - { - return result.View; - } - - StringBuilder locationsText = new StringBuilder(); - foreach (string location in result.SearchedLocations) - { - locationsText.AppendLine(); - locationsText.Append(location); - } - - throw new InvalidOperationException(Resources.FormatCommon_PartialViewNotFound(partialViewName, - locationsText)); - } - public string GenerateIdFromName([NotNull] string name) { return TagBuilder.CreateSanitizedId(name, IdAttributeDotReplacement); diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs index 4223b3573c..8b69c0a7c3 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Microsoft.AspNet.Mvc.Rendering { public interface IViewEngine { - // TODO: Relayer to allow this to be ActionContext. We probably need the common MVC assembly - Task FindView(object actionContext, string viewName); + Task FindView([NotNull] IDictionary context, [NotNull] string viewName); } }