Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
* Remove logic from ViewContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrandenburg committed Oct 16, 2015
1 parent f6e03a2 commit bea9fea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ public ViewContext(
{
throw new ArgumentNullException(nameof(htmlHelperOptions));
}
var service = actionContext.HttpContext.RequestServices;

if (viewData == null)
{
var modelMetadataProvider = service.GetRequiredService<IModelMetadataProvider>();
viewData = new ViewDataDictionary(modelMetadataProvider);
throw new ArgumentNullException(nameof(viewData));
}

if (tempData == null)
{
tempData = service.GetRequiredService<ITempDataDictionary>();
throw new ArgumentNullException(nameof(tempData));
}

View = view;
Expand Down
12 changes: 9 additions & 3 deletions src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponentResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public override async Task ExecuteResultAsync(ActionContext context)
viewData = new ViewDataDictionary(modelMetadataProvider, context.ModelState);
}

var tempData = TempData;
if (tempData == null)
{
tempData = services.GetRequiredService<ITempDataDictionary>();
}

var contentType = ContentType;
if (contentType != null && contentType.Encoding == null)
{
Expand All @@ -93,8 +99,8 @@ public override async Task ExecuteResultAsync(ActionContext context)
// 3. ViewExecutor.DefaultContentType (sensible default)
//
//
response.ContentType =
contentType?.ToString() ??
response.ContentType =
contentType?.ToString() ??
response.ContentType ??
ViewExecutor.DefaultContentType.ToString();

Expand All @@ -110,7 +116,7 @@ public override async Task ExecuteResultAsync(ActionContext context)
context,
NullView.Instance,
viewData,
TempData,
tempData,
writer,
htmlHelperOptions);

Expand Down

0 comments on commit bea9fea

Please sign in to comment.