Replace NotNullAttribute with thrown exceptions

This commit is contained in:
Pranav K 2015-09-25 12:36:05 -07:00
parent eff10cdd66
commit 18c80d156c
106 changed files with 3312 additions and 909 deletions

View File

@ -18,15 +18,7 @@
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.Session": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.Framework.Configuration.Json": "1.0.0-*",
"Microsoft.Framework.PropertyHelper.Sources": {
"version": "1.0.0-*",
"type": "build"
},
"Microsoft.Framework.NotNullAttribute.Sources": {
"type": "build",
"version": "1.0.0-*"
}
"Microsoft.Framework.Configuration.Json": "1.0.0-*"
},
"frameworks": {
"dnx451": { },

View File

@ -15,9 +15,7 @@
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-*",
"Microsoft.Framework.NotNullAttribute.Sources": { "type": "build", "version": "1.0.0-*" },
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }
"Microsoft.AspNet.Tooling.Razor": "1.0.0-*"
},
"frameworks": {
"dnx451": { },

View File

@ -147,14 +147,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
TagBuilder tagBuilder;
if (Route == null)
{
tagBuilder = Generator.GenerateActionLink(linkText: string.Empty,
actionName: Action,
controllerName: Controller,
protocol: Protocol,
hostname: Host,
fragment: Fragment,
routeValues: routeValues,
htmlAttributes: null);
tagBuilder = Generator.GenerateActionLink(
linkText: string.Empty,
actionName: Action,
controllerName: Controller,
protocol: Protocol,
hostname: Host,
fragment: Fragment,
routeValues: routeValues,
htmlAttributes: null);
}
else if (Action != null || Controller != null)
{

View File

@ -104,8 +104,8 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <remarks>
/// <see cref="Controllers.IControllerActivator"/> activates this property while activating controllers.
/// If user code directly instantiates a controller, the getter returns an empty
/// <see cref="Mvc.ActionContext"/>.
/// If user code directly instantiates a controller, the getter returns an empty
/// <see cref="Mvc.ActionContext"/>.
/// </remarks>
[ActionContext]
public ActionContext ActionContext
@ -147,10 +147,13 @@ namespace Microsoft.AspNet.Mvc
return _metadataProvider;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_metadataProvider = value;
}
}
@ -169,10 +172,13 @@ namespace Microsoft.AspNet.Mvc
return _url;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_url = value;
}
}
@ -191,10 +197,13 @@ namespace Microsoft.AspNet.Mvc
return _objectValidator;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_objectValidator = value;
}
}
@ -259,10 +268,13 @@ namespace Microsoft.AspNet.Mvc
return _tempData;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_tempData = value;
}
}
@ -525,8 +537,13 @@ namespace Microsoft.AspNet.Mvc
/// <remarks>Callers should cache an instance of <see cref="JsonSerializerSettings"/> to avoid
/// recreating cached data with each call.</remarks>
[NonAction]
public virtual JsonResult Json(object data, [NotNull] JsonSerializerSettings serializerSettings)
public virtual JsonResult Json(object data, JsonSerializerSettings serializerSettings)
{
if (serializerSettings == null)
{
throw new ArgumentNullException(nameof(serializerSettings));
}
var disposableValue = data as IDisposable;
if (disposableValue != null)
{
@ -981,8 +998,13 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
[NonAction]
public virtual BadRequestObjectResult HttpBadRequest([NotNull] ModelStateDictionary modelState)
public virtual BadRequestObjectResult HttpBadRequest(ModelStateDictionary modelState)
{
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
return new BadRequestObjectResult(modelState);
}
@ -993,8 +1015,13 @@ namespace Microsoft.AspNet.Mvc
/// <param name="value">The content value to format in the entity body.</param>
/// <returns>The created <see cref="CreatedResult"/> for the response.</returns>
[NonAction]
public virtual CreatedResult Created([NotNull] string uri, object value)
public virtual CreatedResult Created(string uri, object value)
{
if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}
var disposableValue = value as IDisposable;
if (disposableValue != null)
{
@ -1011,14 +1038,19 @@ namespace Microsoft.AspNet.Mvc
/// <param name="value">The content value to format in the entity body.</param>
/// <returns>The created <see cref="CreatedResult"/> for the response.</returns>
[NonAction]
public virtual CreatedResult Created([NotNull] Uri uri, object value)
public virtual CreatedResult Created(Uri uri, object value)
{
if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}
var disposableValue = value as IDisposable;
if (disposableValue != null)
{
Response.RegisterForDispose(disposableValue);
}
return new CreatedResult(uri, value);
}
@ -1119,8 +1151,12 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="context">The action executing context.</param>
[NonAction]
public virtual void OnActionExecuting([NotNull] ActionExecutingContext context)
public virtual void OnActionExecuting(ActionExecutingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
}
/// <summary>
@ -1128,8 +1164,12 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="context">The action executed context.</param>
[NonAction]
public virtual void OnActionExecuted([NotNull] ActionExecutedContext context)
public virtual void OnActionExecuted(ActionExecutedContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
}
/// <summary>
@ -1141,9 +1181,19 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> instance.</returns>
[NonAction]
public virtual async Task OnActionExecutionAsync(
[NotNull] ActionExecutingContext context,
[NotNull] ActionExecutionDelegate next)
ActionExecutingContext context,
ActionExecutionDelegate next)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
OnActionExecuting(context);
if (context.Result == null)
{
@ -1160,9 +1210,14 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public virtual Task<bool> TryUpdateModelAsync<TModel>(
[NotNull] TModel model)
TModel model)
where TModel : class
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
return TryUpdateModelAsync(model, prefix: string.Empty);
}
@ -1177,10 +1232,20 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public virtual Task<bool> TryUpdateModelAsync<TModel>(
[NotNull] TModel model,
[NotNull] string prefix)
TModel model,
string prefix)
where TModel : class
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (prefix == null)
{
throw new ArgumentNullException(nameof(prefix));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1204,11 +1269,26 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public virtual Task<bool> TryUpdateModelAsync<TModel>(
[NotNull] TModel model,
[NotNull] string prefix,
[NotNull] IValueProvider valueProvider)
TModel model,
string prefix,
IValueProvider valueProvider)
where TModel : class
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (prefix == null)
{
throw new ArgumentNullException(nameof(prefix));
}
if (valueProvider == null)
{
throw new ArgumentNullException(nameof(valueProvider));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1243,11 +1323,21 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public Task<bool> TryUpdateModelAsync<TModel>(
[NotNull] TModel model,
TModel model,
string prefix,
[NotNull] params Expression<Func<TModel, object>>[] includeExpressions)
params Expression<Func<TModel, object>>[] includeExpressions)
where TModel : class
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (includeExpressions == null)
{
throw new ArgumentNullException(nameof(includeExpressions));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1282,11 +1372,21 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public Task<bool> TryUpdateModelAsync<TModel>(
[NotNull] TModel model,
TModel model,
string prefix,
[NotNull] Func<ModelBindingContext, string, bool> predicate)
Func<ModelBindingContext, string, bool> predicate)
where TModel : class
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1323,12 +1423,27 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public Task<bool> TryUpdateModelAsync<TModel>(
[NotNull] TModel model,
TModel model,
string prefix,
[NotNull] IValueProvider valueProvider,
[NotNull] params Expression<Func<TModel, object>>[] includeExpressions)
IValueProvider valueProvider,
params Expression<Func<TModel, object>>[] includeExpressions)
where TModel : class
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (valueProvider == null)
{
throw new ArgumentNullException(nameof(valueProvider));
}
if (includeExpressions == null)
{
throw new ArgumentNullException(nameof(includeExpressions));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1364,12 +1479,27 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public Task<bool> TryUpdateModelAsync<TModel>(
[NotNull] TModel model,
TModel model,
string prefix,
[NotNull] IValueProvider valueProvider,
[NotNull] Func<ModelBindingContext, string, bool> predicate)
IValueProvider valueProvider,
Func<ModelBindingContext, string, bool> predicate)
where TModel : class
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (valueProvider == null)
{
throw new ArgumentNullException(nameof(valueProvider));
}
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1403,10 +1533,20 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public virtual Task<bool> TryUpdateModelAsync(
[NotNull] object model,
[NotNull] Type modelType,
object model,
Type modelType,
string prefix)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (modelType == null)
{
throw new ArgumentNullException(nameof(modelType));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1442,12 +1582,32 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful.</returns>
[NonAction]
public Task<bool> TryUpdateModelAsync(
[NotNull] object model,
[NotNull] Type modelType,
object model,
Type modelType,
string prefix,
[NotNull] IValueProvider valueProvider,
[NotNull] Func<ModelBindingContext, string, bool> predicate)
IValueProvider valueProvider,
Func<ModelBindingContext, string, bool> predicate)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (modelType == null)
{
throw new ArgumentNullException(nameof(modelType));
}
if (valueProvider == null)
{
throw new ArgumentNullException(nameof(valueProvider));
}
if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(
@ -1478,8 +1638,13 @@ namespace Microsoft.AspNet.Mvc
/// <returns><c>true</c> if the <see cref="ModelState"/> is valid; <c>false</c> otherwise.</returns>
[NonAction]
public virtual bool TryValidateModel(
[NotNull] object model)
object model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
return TryValidateModel(model, prefix: null);
}
@ -1492,9 +1657,14 @@ namespace Microsoft.AspNet.Mvc
/// <returns><c>true</c> if the <see cref="ModelState"/> is valid;<c>false</c> otherwise.</returns>
[NonAction]
public virtual bool TryValidateModel(
[NotNull] object model,
object model,
string prefix)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (BindingContext == null)
{
var message = Resources.FormatPropertyOfTypeCannotBeNull(

View File

@ -1,9 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection
{
@ -18,9 +17,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
/// <param name="setupAction">The <see cref="MvcViewOptions"/> which need to be configured.</param>
public static IMvcBuilder AddViewOptions(
[NotNull] this IMvcBuilder builder,
[NotNull] Action<MvcViewOptions> setupAction)
this IMvcBuilder builder,
Action<MvcViewOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure(setupAction);
return builder;
}

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
@ -11,24 +11,38 @@ using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Mvc.ViewFeatures.Internal;
using Microsoft.Framework.DependencyInjection.Extensions;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.Framework.DependencyInjection
{
public static class MvcViewFeaturesMvcCoreBuilderExtensions
{
public static IMvcCoreBuilder AddViews([NotNull] this IMvcCoreBuilder builder)
public static IMvcCoreBuilder AddViews(this IMvcCoreBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
builder.AddDataAnnotations();
AddViewServices(builder.Services);
return builder;
}
public static IMvcCoreBuilder AddViews(
[NotNull] this IMvcCoreBuilder builder,
[NotNull] Action<MvcViewOptions> setupAction)
this IMvcCoreBuilder builder,
Action<MvcViewOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.AddDataAnnotations();
AddViewServices(builder.Services);
@ -41,9 +55,19 @@ namespace Microsoft.Framework.DependencyInjection
}
public static IMvcCoreBuilder ConfigureViews(
[NotNull] this IMvcCoreBuilder builder,
[NotNull] Action<MvcViewOptions> setupAction)
this IMvcCoreBuilder builder,
Action<MvcViewOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure(setupAction);
return builder;
}

View File

@ -3,7 +3,6 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ViewComponents;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -16,7 +15,7 @@ namespace Microsoft.AspNet.Mvc
/// Executes the result of a <see cref="ViewComponent"/> using the specified <paramref name="context"/>.
/// </summary>
/// <param name="context">The <see cref="ViewComponentContext"/> for the current component execution.</param>
void Execute([NotNull] ViewComponentContext context);
void Execute(ViewComponentContext context);
/// <summary>
/// Asynchronously executes the result of a <see cref="ViewComponent"/> using the specified
@ -24,6 +23,6 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="context">The <see cref="ViewComponentContext"/> for the current component execution.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous execution.</returns>
Task ExecuteAsync([NotNull] ViewComponentContext context);
Task ExecuteAsync(ViewComponentContext context);
}
}

View File

@ -2,12 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
{
public interface ICanHasViewContext
{
void Contextualize([NotNull] ViewContext viewContext);
void Contextualize(ViewContext viewContext);
}
}

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
{
@ -14,8 +14,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
public string Path => string.Empty;
public Task RenderAsync([NotNull] ViewContext context)
public Task RenderAsync(ViewContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return Task.FromResult(0);
}
}

View File

@ -5,8 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
{
@ -62,8 +60,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
{
private Dictionary<string, int> _ordering = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
public ErrorsOrderer([NotNull] ModelMetadata metadata)
public ErrorsOrderer(ModelMetadata metadata)
{
if (metadata == null)
{
throw new ArgumentNullException(nameof(metadata));
}
foreach (var data in metadata.Properties)
{
_ordering[data.PropertyName] = data.Order;

View File

@ -1,12 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -15,10 +14,24 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
public class MvcViewOptions
{
private HtmlHelperOptions _htmlHelperOptions = new HtmlHelperOptions();
/// <summary>
/// Gets or sets programmatic configuration for the HTML helpers and <see cref="ViewContext"/>.
/// Gets or sets programmatic configuration for the HTML helpers and <see cref="Rendering.ViewContext"/>.
/// </summary>
public HtmlHelperOptions HtmlHelperOptions { get;[param: NotNull] set; } = new HtmlHelperOptions();
public HtmlHelperOptions HtmlHelperOptions
{
get { return _htmlHelperOptions; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_htmlHelperOptions = value;
}
}
/// <summary>
/// Gets a list <see cref="IViewEngine"/>s used by this application.

View File

@ -4,7 +4,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
using Microsoft.Net.Http.Headers;
using Microsoft.Framework.OptionsModel;
@ -54,8 +53,13 @@ namespace Microsoft.AspNet.Mvc
public MediaTypeHeaderValue ContentType { get; set; }
/// <inheritdoc />
public override async Task ExecuteResultAsync([NotNull] ActionContext context)
public override async Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var viewEngine = ViewEngine ??
context.HttpContext.RequestServices.GetRequiredService<ICompositeViewEngine>();

View File

@ -11,7 +11,6 @@ using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.AspNet.Mvc.Routing;
namespace Microsoft.AspNet.Mvc
@ -192,8 +191,13 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="context">The <see cref="ClientModelValidationContext"/> used to generate the URL.</param>
/// <returns>The URL where the client should send a validation request.</returns>
protected virtual string GetUrl([NotNull] ClientModelValidationContext context)
protected virtual string GetUrl(ClientModelValidationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var urlHelper = context.RequestServices.GetRequiredService<IUrlHelper>();
var url = urlHelper.RouteUrl(new UrlRouteContext()
{
@ -230,8 +234,13 @@ namespace Microsoft.AspNet.Mvc
/// Thrown if unable to generate a target URL for a validation request.
/// </exception>
public virtual IEnumerable<ModelClientValidationRule> GetClientValidationRules(
[NotNull] ClientModelValidationContext context)
ClientModelValidationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var metadata = context.ModelMetadata;
var rule = new ModelClientValidationRemoteRule(
FormatErrorMessage(metadata.GetDisplayName()),

View File

@ -4,7 +4,6 @@
using System;
using System.Linq.Expressions;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -37,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent Display([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent Display(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
}
@ -73,10 +77,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression,
templateName: null,
@ -111,10 +120,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string templateName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(expression, templateName, htmlFieldName: null, additionalViewData: null);
}
@ -150,11 +164,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string templateName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression,
templateName,
@ -193,11 +212,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent Display(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string templateName,
string htmlFieldName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(expression, templateName, htmlFieldName, additionalViewData: null);
}
@ -221,9 +245,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DisplayFor<TResult>(
expression,
templateName: null,
@ -257,10 +291,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DisplayFor<TResult>(
expression,
templateName: null,
@ -290,10 +334,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string templateName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DisplayFor<TResult>(
expression,
templateName,
@ -328,11 +382,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string templateName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DisplayFor<TResult>(
expression,
templateName,
@ -366,11 +430,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string templateName,
string htmlFieldName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DisplayFor<TResult>(
expression,
templateName: templateName,
@ -394,8 +468,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper)
public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression: null,
templateName: null,
@ -424,8 +503,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData)
public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper, object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression: null,
templateName: null,
@ -450,8 +534,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent DisplayForModel([NotNull] this IHtmlHelper htmlHelper, string templateName)
public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper, string templateName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression: null,
templateName: templateName,
@ -483,10 +572,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayForModel(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string templateName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression: null,
templateName: templateName,
@ -517,10 +611,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayForModel(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression: null,
templateName: templateName,
@ -556,11 +655,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent DisplayForModel(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Display(
expression: null,
templateName: templateName,

View File

@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -19,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </summary>
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <returns>A <see cref="string"/> containing the display name.</returns>
public static string DisplayNameForModel([NotNull] this IHtmlHelper htmlHelper)
public static string DisplayNameForModel(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.DisplayName(expression: null);
}
@ -36,9 +39,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A <see cref="string"/> containing the display name.</returns>
public static string DisplayNameFor<TModelItem, TResult>(
[NotNull] this IHtmlHelper<IEnumerable<TModelItem>> htmlHelper,
[NotNull] Expression<Func<TModelItem, TResult>> expression)
this IHtmlHelper<IEnumerable<TModelItem>> htmlHelper,
Expression<Func<TModelItem, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DisplayNameForInnerType<TModelItem, TResult>(expression);
}
}

View File

@ -4,8 +4,6 @@
using System;
using System.Linq.Expressions;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -38,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent Editor([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent Editor(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
}
@ -55,8 +58,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <param name="additionalViewData">
/// An anonymous <see cref="object"/> or <see cref="System.Collections.Generic.IDictionary{string, object}"/>
/// that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/>
/// instance created for the template.
/// that can contain additional view data that will be merged into the
/// <see cref="ViewFeatures.ViewDataDictionary{TModel}"/> instance created for the template.
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element(s).</returns>
/// <remarks>
@ -74,10 +77,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent Editor(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression,
templateName: null,
@ -111,8 +119,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent Editor([NotNull] this IHtmlHelper htmlHelper, string expression, string templateName)
public static IHtmlContent Editor(this IHtmlHelper htmlHelper, string expression, string templateName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(expression, templateName, htmlFieldName: null, additionalViewData: null);
}
@ -129,8 +142,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="templateName">The name of the template used to create the HTML markup.</param>
/// <param name="additionalViewData">
/// An anonymous <see cref="object"/> or <see cref="System.Collections.Generic.IDictionary{string, object}"/>
/// that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/>
/// instance created for the template.
/// that can contain additional view data that will be merged into the
/// <see cref="ViewFeatures.ViewDataDictionary{TModel}"/> instance created for the template.
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element(s).</returns>
/// <remarks>
@ -148,11 +161,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent Editor(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string templateName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression,
templateName,
@ -191,11 +209,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent Editor(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string templateName,
string htmlFieldName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(expression, templateName, htmlFieldName, additionalViewData: null);
}
@ -219,9 +242,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.EditorFor(expression, templateName: null, htmlFieldName: null, additionalViewData: null);
}
@ -234,8 +267,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">An expression to be evaluated against the current model.</param>
/// <param name="additionalViewData">
/// An anonymous <see cref="object"/> or <see cref="System.Collections.Generic.IDictionary{string, object}"/>
/// that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/>
/// instance created for the template.
/// that can contain additional view data that will be merged into the
/// <see cref="ViewFeatures.ViewDataDictionary{TModel}"/> instance created for the template.
/// </param>
/// <typeparam name="TModel">The type of the model.</typeparam>
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
@ -251,10 +284,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.EditorFor(
expression,
templateName: null,
@ -284,10 +327,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string templateName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.EditorFor(expression, templateName, htmlFieldName: null, additionalViewData: null);
}
@ -301,8 +354,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="templateName">The name of the template that is used to create the HTML markup.</param>
/// <param name="additionalViewData">
/// An anonymous <see cref="object"/> or <see cref="System.Collections.Generic.IDictionary{string, object}"/>
/// that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/>
/// instance created for the template.
/// that can contain additional view data that will be merged into the
/// <see cref="ViewFeatures.ViewDataDictionary{TModel}"/> instance created for the template.
/// </param>
/// <typeparam name="TModel">The type of the model.</typeparam>
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
@ -318,11 +371,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string templateName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.EditorFor(
expression,
templateName,
@ -356,11 +419,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string templateName,
string htmlFieldName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.EditorFor(expression, templateName, htmlFieldName, additionalViewData: null);
}
@ -380,8 +453,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper)
public static IHtmlContent EditorForModel(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression: null,
templateName: null,
@ -396,8 +474,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <param name="additionalViewData">
/// An anonymous <see cref="object"/> or <see cref="System.Collections.Generic.IDictionary{string, object}"/>
/// that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/>
/// instance created for the template.
/// that can contain additional view data that will be merged into the
/// <see cref="ViewFeatures.ViewDataDictionary{TModel}"/> instance created for the template.
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element(s).</returns>
/// <remarks>
@ -410,8 +488,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper, object additionalViewData)
public static IHtmlContent EditorForModel(this IHtmlHelper htmlHelper, object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression: null,
templateName: null,
@ -436,8 +519,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// case-sensitive file systems.
/// </para>
/// </remarks>
public static IHtmlContent EditorForModel([NotNull] this IHtmlHelper htmlHelper, string templateName)
public static IHtmlContent EditorForModel(this IHtmlHelper htmlHelper, string templateName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression: null,
templateName: templateName,
@ -454,8 +542,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="templateName">The name of the template used to create the HTML markup.</param>
/// <param name="additionalViewData">
/// An anonymous <see cref="object"/> or <see cref="System.Collections.Generic.IDictionary{string, object}"/>
/// that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/>
/// instance created for the template.
/// that can contain additional view data that will be merged into the
/// <see cref="ViewFeatures.ViewDataDictionary{TModel}"/> instance created for the template.
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element(s).</returns>
/// <remarks>
@ -469,10 +557,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorForModel(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string templateName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression: null,
templateName: templateName,
@ -503,10 +596,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorForModel(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression: null,
templateName: templateName,
@ -527,8 +625,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <param name="additionalViewData">
/// An anonymous <see cref="object"/> or <see cref="System.Collections.Generic.IDictionary{string, object}"/>
/// that can contain additional view data that will be merged into the <see cref="ViewDataDictionary{TModel}"/>
/// instance created for the template.
/// that can contain additional view data that will be merged into the
/// <see cref="ViewFeatures.ViewDataDictionary{TModel}"/> instance created for the template.
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element(s).</returns>
/// <remarks>
@ -542,11 +640,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent EditorForModel(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string templateName,
string htmlFieldName,
object additionalViewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Editor(
expression: null,
templateName: templateName,

View File

@ -1,8 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
using System;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper)
public static MvcForm BeginForm(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
// Generates <form action="{current url}" method="post">.
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null,
method: FormMethod.Post, htmlAttributes: null);
@ -41,8 +45,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper, FormMethod method)
public static MvcForm BeginForm(this IHtmlHelper htmlHelper, FormMethod method)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null,
method: method, htmlAttributes: null);
}
@ -65,10 +74,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
FormMethod method,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: null,
method: method, htmlAttributes: htmlAttributes);
}
@ -91,8 +105,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm([NotNull] this IHtmlHelper htmlHelper, object routeValues)
public static MvcForm BeginForm(this IHtmlHelper htmlHelper, object routeValues)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName: null, controllerName: null, routeValues: routeValues,
method: FormMethod.Post, htmlAttributes: null);
}
@ -111,10 +130,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string actionName,
string controllerName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName, controllerName, routeValues: null,
method: FormMethod.Post, htmlAttributes: null);
}
@ -140,11 +164,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
object routeValues)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName, controllerName, routeValues,
FormMethod.Post, htmlAttributes: null);
}
@ -164,11 +193,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
FormMethod method)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName, controllerName, routeValues: null,
method: method, htmlAttributes: null);
}
@ -195,12 +229,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
object routeValues,
FormMethod method)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName, controllerName, routeValues,
method, htmlAttributes: null);
}
@ -225,12 +264,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string actionName,
string controllerName,
FormMethod method,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginForm(actionName, controllerName, routeValues: null,
method: method, htmlAttributes: htmlAttributes);
}
@ -253,8 +297,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginRouteForm([NotNull] this IHtmlHelper htmlHelper, object routeValues)
public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, object routeValues)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginRouteForm(
routeName: null,
routeValues: routeValues,
@ -274,8 +323,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginRouteForm([NotNull] this IHtmlHelper htmlHelper, string routeName)
public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, string routeName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginRouteForm(
routeName,
routeValues: null,
@ -303,10 +357,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginRouteForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string routeName,
object routeValues)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginRouteForm(routeName, routeValues, FormMethod.Post, htmlAttributes: null);
}
@ -324,10 +383,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginRouteForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string routeName,
FormMethod method)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginRouteForm(routeName, routeValues: null, method: method, htmlAttributes: null);
}
@ -352,11 +416,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginRouteForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string routeName,
object routeValues,
FormMethod method)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginRouteForm(routeName, routeValues, method, htmlAttributes: null);
}
@ -379,11 +448,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static MvcForm BeginRouteForm(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string routeName,
FormMethod method,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.BeginRouteForm(
routeName,
routeValues: null,

View File

@ -4,8 +4,6 @@
using System;
using System.Linq.Expressions;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -23,8 +21,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; elements.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set checkbox
/// element's "name" attribute. Sanitizes <paramref name="expression"/> to set checkbox element's "id"
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// checkbox element's "name" attribute. Sanitizes <paramref name="expression"/> to set checkbox element's "id"
/// attribute.
/// </para>
/// <para>Determines checkbox element's "checked" attribute based on the following precedence:</para>
@ -34,8 +32,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// fully-qualified name) if entry exists and can be converted to a <see cref="bool"/>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="bool"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="bool"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -50,8 +48,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// value "checked" if the <see cref="bool"/> values is <c>true</c>; does not include the attribute otherwise.
/// </para>
/// </remarks>
public static IHtmlContent CheckBox([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent CheckBox(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.CheckBox(expression, isChecked: null, htmlAttributes: null);
}
@ -65,8 +68,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; elements.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set checkbox
/// element's "name" attribute. Sanitizes <paramref name="expression"/> to set checkbox element's "id"
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// checkbox element's "name" attribute. Sanitizes <paramref name="expression"/> to set checkbox element's "id"
/// attribute.
/// </para>
/// <para>Determines checkbox element's "checked" attribute based on the following precedence:</para>
@ -77,8 +80,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </item>
/// <item><paramref name="isChecked"/> if non-<c>null</c>.</item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="bool"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="bool"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -94,10 +97,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent CheckBox(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
bool isChecked)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.CheckBox(expression, isChecked, htmlAttributes: null);
}
@ -115,8 +123,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; elements.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set checkbox
/// element's "name" attribute. Sanitizes <paramref name="expression"/> to set checkbox element's "id"
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// checkbox element's "name" attribute. Sanitizes <paramref name="expression"/> to set checkbox element's "id"
/// attribute.
/// </para>
/// <para>Determines checkbox element's "checked" attribute based on the following precedence:</para>
@ -126,8 +134,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// fully-qualified name) if entry exists and can be converted to a <see cref="bool"/>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="bool"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="bool"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -144,10 +152,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent CheckBox(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.CheckBox(expression, isChecked: null, htmlAttributes: htmlAttributes);
}
@ -160,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; elements.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set checkbox element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set checkbox element's "id" attribute.
/// </para>
@ -182,9 +195,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent CheckBoxFor<TModel>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, bool>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, bool>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.CheckBoxFor(expression, htmlAttributes: null);
}
@ -196,7 +219,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -207,8 +230,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -219,8 +242,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <item>Otherwise, <c>string.Empty</c>.</item>
/// </list>
/// </remarks>
public static IHtmlContent Hidden([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent Hidden(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Hidden(expression, value: null, htmlAttributes: null);
}
@ -233,7 +261,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -245,8 +273,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </item>
/// <item><paramref name="value"/> if non-<c>null</c>.</item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -258,10 +286,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent Hidden(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Hidden(expression, value, htmlAttributes: null);
}
@ -275,7 +308,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;input&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </para>
@ -293,9 +326,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent HiddenFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.HiddenFor(expression, htmlAttributes: null);
}
@ -306,12 +349,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">Expression name, relative to the current model.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute. Sets &lt;input&gt; element's "value" attribute to <c>string.Empty</c>.
/// </remarks>
public static IHtmlContent Password([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent Password(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Password(expression, value: null, htmlAttributes: null);
}
@ -324,7 +372,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -335,10 +383,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent Password(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Password(expression, value, htmlAttributes: null);
}
@ -352,7 +405,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;input&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </para>
@ -366,9 +419,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent PasswordFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.PasswordFor(expression, htmlAttributes: null);
}
@ -381,7 +444,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute. Sets &lt;input&gt; element's "value" attribute to <paramref name="value"/>.
/// </para>
@ -392,8 +455,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -411,10 +474,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent RadioButton(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.RadioButton(expression, value, isChecked: null, htmlAttributes: null);
}
@ -435,7 +503,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -453,8 +521,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </item>
/// <item>Existing "checked" entry in <paramref name="htmlAttributes"/> if any.</item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -472,11 +540,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent RadioButton(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.RadioButton(expression, value, isChecked: null, htmlAttributes: htmlAttributes);
}
@ -496,7 +569,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -513,8 +586,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </item>
/// <item><paramref name="isChecked"/> if non-<c>null</c>.</item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -532,11 +605,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent RadioButton(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value,
bool isChecked)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.RadioButton(expression, value, isChecked, htmlAttributes: null);
}
@ -551,7 +629,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;select&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute. Converts the
/// <paramref name="value"/> to a <see cref="string"/> to set element's "value" attribute.
@ -574,10 +652,25 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
public static IHtmlContent RadioButtonFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
[NotNull] object value)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
object value)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
return htmlHelper.RadioButtonFor(expression, value, htmlAttributes: null);
}
@ -589,7 +682,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -600,8 +693,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -612,8 +705,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <item>Otherwise, <c>string.Empty</c>.</item>
/// </list>
/// </remarks>
public static IHtmlContent TextBox([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent TextBox(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextBox(expression, value: null, format: null, htmlAttributes: null);
}
@ -626,7 +724,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -640,8 +738,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="value"/> if non-<c>null</c>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -653,10 +751,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextBox(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextBox(expression, value, format: null, htmlAttributes: null);
}
@ -672,7 +775,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -688,8 +791,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="format"/> is <c>null</c> or empty.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>. Formats entry using
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>. Formats entry using
/// <paramref name="format"/> or converts entry to a <see cref="string"/> directly if <paramref name="format"/>
/// is <c>null</c> or empty.
/// </item>
@ -704,11 +807,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextBox(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value,
string format)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextBox(expression, value, format, htmlAttributes: null);
}
@ -726,7 +834,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;input&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -740,8 +848,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="value"/> if non-<c>null</c>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -754,11 +862,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextBox(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object value,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextBox(expression, value, format: null, htmlAttributes: htmlAttributes);
}
@ -772,7 +885,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;input&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </para>
@ -789,9 +902,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextBoxFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.TextBoxFor(expression, format: null, htmlAttributes: null);
}
@ -808,7 +931,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;input&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </para>
@ -827,10 +950,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextBoxFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string format)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.TextBoxFor(expression, format, htmlAttributes: null);
}
@ -849,7 +982,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;input&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;input&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </para>
@ -867,10 +1000,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextBoxFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.TextBoxFor(expression, format: null, htmlAttributes: htmlAttributes);
}
@ -882,7 +1025,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;textarea&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;textarea&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -893,8 +1036,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -906,9 +1049,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextArea(expression, value: null, rows: 0, columns: 0, htmlAttributes: null);
}
@ -925,7 +1073,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;textarea&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;textarea&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -936,8 +1084,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -949,10 +1097,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextArea(expression, value: null, rows: 0, columns: 0, htmlAttributes: htmlAttributes);
}
@ -965,7 +1118,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;textarea&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;textarea&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -977,8 +1130,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </item>
/// <item><paramref name="value"/> if non-<c>null</c>.</item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -990,10 +1143,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string value)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextArea(expression, value, rows: 0, columns: 0, htmlAttributes: null);
}
@ -1011,7 +1169,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;textarea&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;textarea&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </para>
@ -1023,8 +1181,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </item>
/// <item><paramref name="value"/> if non-<c>null</c>.</item>
/// <item>
/// <see cref="ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a fully-qualified
/// name) if entry exists and can be converted to a <see cref="string"/>.
/// <see cref="ViewFeatures.ViewDataDictionary"/> entry for <paramref name="expression"/> (converted to a
/// fully-qualified name) if entry exists and can be converted to a <see cref="string"/>.
/// </item>
/// <item>
/// Linq expression based on <paramref name="expression"/> (converted to a fully-qualified name) run against
@ -1036,11 +1194,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextArea(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string value,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.TextArea(expression, value, rows: 0, columns: 0, htmlAttributes: htmlAttributes);
}
@ -1054,7 +1217,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;textarea&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;textarea&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </para>
@ -1071,9 +1234,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextAreaFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.TextAreaFor(expression, rows: 0, columns: 0, htmlAttributes: null);
}
@ -1092,7 +1265,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;textarea&gt; element.</returns>
/// <remarks>
/// <para>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;textarea&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </para>
@ -1109,10 +1282,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
public static IHtmlContent TextAreaFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.TextAreaFor(expression, rows: 0, columns: 0, htmlAttributes: htmlAttributes);
}
}

View File

@ -4,8 +4,6 @@
using System;
using System.Linq.Expressions;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -20,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <param name="expression">Expression name, relative to the current model.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent Label([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent Label(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Label(expression, labelText: null, htmlAttributes: null);
}
@ -32,8 +35,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">Expression name, relative to the current model.</param>
/// <param name="labelText">The inner text of the element.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent Label([NotNull] this IHtmlHelper htmlHelper, string expression, string labelText)
public static IHtmlContent Label(this IHtmlHelper htmlHelper, string expression, string labelText)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Label(expression, labelText, htmlAttributes: null);
}
@ -46,9 +54,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent LabelFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.LabelFor<TResult>(expression, labelText: null, htmlAttributes: null);
}
@ -62,10 +80,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent LabelFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string labelText)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.LabelFor<TResult>(expression, labelText, htmlAttributes: null);
}
@ -83,10 +111,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent LabelFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.LabelFor<TResult>(expression, labelText: null, htmlAttributes: htmlAttributes);
}
@ -95,8 +133,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </summary>
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper)
public static IHtmlContent LabelForModel(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Label(expression: null, labelText: null, htmlAttributes: null);
}
@ -106,8 +149,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <param name="labelText">The inner text of the element.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper, string labelText)
public static IHtmlContent LabelForModel(this IHtmlHelper htmlHelper, string labelText)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Label(expression: null, labelText: labelText, htmlAttributes: null);
}
@ -121,8 +169,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// attributes.
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent LabelForModel([NotNull] this IHtmlHelper htmlHelper, object htmlAttributes)
public static IHtmlContent LabelForModel(this IHtmlHelper htmlHelper, object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Label(expression: null, labelText: null, htmlAttributes: htmlAttributes);
}
@ -138,10 +191,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
public static IHtmlContent LabelForModel(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string labelText,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Label(expression: null, labelText: labelText, htmlAttributes: htmlAttributes);
}
}

View File

@ -1,9 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -20,10 +19,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="actionName">The name of the action.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
this IHtmlHelper helper,
string linkText,
string actionName)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return helper.ActionLink(
linkText,
actionName,
@ -50,11 +59,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
this IHtmlHelper helper,
string linkText,
string actionName,
object routeValues)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return helper.ActionLink(
linkText,
actionName,
@ -86,12 +105,22 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
this IHtmlHelper helper,
string linkText,
string actionName,
object routeValues,
object htmlAttributes)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return helper.ActionLink(
linkText,
actionName,
@ -112,11 +141,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="controllerName">The name of the controller.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
this IHtmlHelper helper,
string linkText,
string actionName,
string controllerName)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return helper.ActionLink(
linkText,
actionName,
@ -144,12 +183,22 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
this IHtmlHelper helper,
string linkText,
string actionName,
string controllerName,
object routeValues)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return helper.ActionLink(
linkText,
actionName,
@ -182,13 +231,23 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent ActionLink(
[NotNull] this IHtmlHelper helper,
[NotNull] string linkText,
this IHtmlHelper helper,
string linkText,
string actionName,
string controllerName,
object routeValues,
object htmlAttributes)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return helper.ActionLink(
linkText,
actionName,
@ -214,10 +273,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
this IHtmlHelper htmlHelper,
string linkText,
object routeValues)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return htmlHelper.RouteLink(
linkText,
routeName: null,
@ -236,10 +305,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="routeName">The name of the route.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
this IHtmlHelper htmlHelper,
string linkText,
string routeName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return htmlHelper.RouteLink(
linkText,
routeName,
@ -265,11 +344,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
this IHtmlHelper htmlHelper,
string linkText,
string routeName,
object routeValues)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return htmlHelper.RouteLink(
linkText,
routeName,
@ -299,11 +388,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
this IHtmlHelper htmlHelper,
string linkText,
object routeValues,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return htmlHelper.RouteLink(
linkText,
routeName: null,
@ -334,12 +433,22 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
public static IHtmlContent RouteLink(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string linkText,
this IHtmlHelper htmlHelper,
string linkText,
string routeName,
object routeValues,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
return htmlHelper.RouteLink(
linkText,
routeName,

View File

@ -1,8 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
using System;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -16,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </summary>
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <returns>A <see cref="string"/> containing the element name.</returns>
public static string NameForModel([NotNull] this IHtmlHelper htmlHelper)
public static string NameForModel(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Name(expression: null);
}
@ -26,8 +30,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </summary>
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
/// <returns>A <see cref="string"/> containing the element Id.</returns>
public static string IdForModel([NotNull] this IHtmlHelper htmlHelper)
public static string IdForModel(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Id(expression: null);
}
}

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -25,9 +25,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the created HTML.
/// </returns>
public static Task<IHtmlContent> PartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName)
this IHtmlHelper htmlHelper,
string partialViewName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null);
}
@ -44,10 +54,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the created HTML.
/// </returns>
public static Task<IHtmlContent> PartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
this IHtmlHelper htmlHelper,
string partialViewName,
ViewDataDictionary viewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData);
}
@ -64,10 +84,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// the created HTML.
/// </returns>
public static Task<IHtmlContent> PartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
this IHtmlHelper htmlHelper,
string partialViewName,
object model)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return htmlHelper.PartialAsync(partialViewName, model, viewData: null);
}
@ -86,9 +116,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <see cref="IHtmlHelper.PartialAsync(string, object, ViewDataDictionary)"/>
/// </remarks>
public static IHtmlContent Partial(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName)
this IHtmlHelper htmlHelper,
string partialViewName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData: null);
}
@ -108,10 +148,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <see cref="IHtmlHelper.PartialAsync(string, object, ViewDataDictionary)"/>
/// </remarks>
public static IHtmlContent Partial(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
this IHtmlHelper htmlHelper,
string partialViewName,
ViewDataDictionary viewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData);
}
@ -131,10 +181,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <see cref="IHtmlHelper.PartialAsync(string, object, ViewDataDictionary)"/>
/// </remarks>
public static IHtmlContent Partial(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
this IHtmlHelper htmlHelper,
string partialViewName,
object model)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return Partial(htmlHelper, partialViewName, model, viewData: null);
}
@ -155,11 +215,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <see cref="IHtmlHelper.PartialAsync(string, object, ViewDataDictionary)"/>
/// </remarks>
public static IHtmlContent Partial(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
this IHtmlHelper htmlHelper,
string partialViewName,
object model,
ViewDataDictionary viewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
var result = htmlHelper.PartialAsync(partialViewName, model, viewData);
return result.GetAwaiter().GetResult();
}
@ -176,9 +246,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static Task RenderPartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName)
this IHtmlHelper htmlHelper,
string partialViewName)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model,
viewData: htmlHelper.ViewData);
}
@ -196,10 +276,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static Task RenderPartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
this IHtmlHelper htmlHelper,
string partialViewName,
ViewDataDictionary viewData)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: viewData);
}
@ -216,10 +306,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
public static Task RenderPartialAsync(
[NotNull] this IHtmlHelper htmlHelper,
[NotNull] string partialViewName,
this IHtmlHelper htmlHelper,
string partialViewName,
object model)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return htmlHelper.RenderPartialAsync(partialViewName, model, htmlHelper.ViewData);
}
}

View File

@ -5,8 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -22,12 +20,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">Expression name, relative to the current model.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;select&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </remarks>
public static IHtmlContent DropDownList([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent DropDownList(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.DropDownList(expression, selectList: null, optionLabel: null, htmlAttributes: null);
}
@ -42,15 +45,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;select&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </remarks>
public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string optionLabel)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.DropDownList(
expression,
selectList: null,
@ -70,15 +78,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;select&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </remarks>
public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
IEnumerable<SelectListItem> selectList)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.DropDownList(expression, selectList, optionLabel: null, htmlAttributes: null);
}
@ -98,16 +111,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;select&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </remarks>
public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
IEnumerable<SelectListItem> selectList,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.DropDownList(expression, selectList, optionLabel: null, htmlAttributes: htmlAttributes);
}
@ -126,16 +144,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;select&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </remarks>
public static IHtmlContent DropDownList(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
IEnumerable<SelectListItem> selectList,
string optionLabel)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.DropDownList(expression, selectList, optionLabel, htmlAttributes: null);
}
@ -153,15 +176,25 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;select&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </remarks>
public static IHtmlContent DropDownListFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DropDownListFor(expression, selectList, optionLabel: null, htmlAttributes: null);
}
@ -183,16 +216,26 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;select&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </remarks>
public static IHtmlContent DropDownListFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DropDownListFor(
expression,
selectList,
@ -217,16 +260,26 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;select&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </remarks>
public static IHtmlContent DropDownListFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList,
string optionLabel)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.DropDownListFor(expression, selectList, optionLabel, htmlAttributes: null);
}
@ -237,12 +290,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">Expression name, relative to the current model.</param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;select&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </remarks>
public static IHtmlContent ListBox([NotNull] this IHtmlHelper htmlHelper, string expression)
public static IHtmlContent ListBox(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ListBox(expression, selectList: null, htmlAttributes: null);
}
@ -258,15 +316,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and <paramref name="expression"/> to set
/// &lt;select&gt; element's "name" attribute. Sanitizes <paramref name="expression"/> to set element's "id"
/// attribute.
/// </remarks>
public static IHtmlContent ListBox(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
IEnumerable<SelectListItem> selectList)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ListBox(expression, selectList, htmlAttributes: null);
}
@ -284,15 +347,25 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;select&gt; element.</returns>
/// <remarks>
/// Combines <see cref="TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// Combines <see cref="ViewFeatures.TemplateInfo.HtmlFieldPrefix"/> and the string representation of the
/// <paramref name="expression"/> to set &lt;select&gt; element's "name" attribute. Sanitizes the string
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </remarks>
public static IHtmlContent ListBoxFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.ListBoxFor(expression, selectList, htmlAttributes: null);
}
}

View File

@ -4,8 +4,6 @@
using System;
using System.Linq.Expressions;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -29,9 +27,14 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// will always be visible but client-side validation may update the associated CSS class.
/// </remarks>
public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationMessage(expression, message: null, htmlAttributes: null, tag: null);
}
@ -51,10 +54,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <c>null</c> if the <paramref name="expression"/> is valid and client-side validation is disabled.
/// </returns>
public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string message)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationMessage(expression, message, htmlAttributes: null, tag: null);
}
@ -79,10 +87,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// will always be visible but client-side validation may update the associated CSS class.
/// </remarks>
public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationMessage(expression, message: null, htmlAttributes: htmlAttributes, tag: null);
}
@ -106,11 +119,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="expression"/> is valid and client-side validation is disabled.
/// </returns>
public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string message,
string tag)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationMessage(expression, message, htmlAttributes: null, tag: tag);
}
@ -136,11 +154,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <c>null</c> if the <paramref name="expression"/> is valid and client-side validation is disabled.
/// </returns>
public static IHtmlContent ValidationMessage(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string expression,
string message,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationMessage(expression, message, htmlAttributes, tag: null);
}
@ -161,9 +184,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// will always be visible but client-side validation may update the associated CSS class.
/// </remarks>
public static IHtmlContent ValidationMessageFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.ValidationMessageFor(expression, message: null, htmlAttributes: null, tag: null);
}
@ -185,10 +218,20 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <c>null</c> if the <paramref name="expression"/> is valid and client-side validation is disabled.
/// </returns>
public static IHtmlContent ValidationMessageFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string message)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.ValidationMessageFor(expression, message, htmlAttributes: null, tag: null);
}
@ -216,11 +259,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <c>null</c> if the <paramref name="expression"/> is valid and client-side validation is disabled.
/// </returns>
public static IHtmlContent ValidationMessageFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string message,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.ValidationMessageFor(expression, message, htmlAttributes, tag: null);
}
@ -246,11 +299,21 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="expression"/> is valid and client-side validation is disabled.
/// </returns>
public static IHtmlContent ValidationMessageFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression,
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression,
string message,
string tag)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.ValidationMessageFor(expression, message, htmlAttributes: null, tag: tag);
}
@ -263,8 +326,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// New <see cref="IHtmlContent"/> containing a &lt;div&gt; element wrapping the &lt;ul&gt; element.
/// <see cref="HtmlString.Empty"/> if the current model is valid and client-side validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper)
public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
message: null,
@ -284,8 +352,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// New <see cref="IHtmlContent"/> containing a &lt;div&gt; element wrapping the &lt;ul&gt; element.
/// <see cref="HtmlString.Empty"/> if the current model is valid and client-side validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, bool excludePropertyErrors)
public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, bool excludePropertyErrors)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors,
message: null,
@ -305,8 +378,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="message"/>) and the &lt;ul&gt; element. <see cref="HtmlString.Empty"/> if the current model
/// is valid and client-side validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message)
public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
message: message,
@ -329,8 +407,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// and the &lt;ul&gt; element. <see cref="HtmlString.Empty"/> if the current model is valid and client-side
/// validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary([NotNull] this IHtmlHelper htmlHelper, string message, string tag)
public static IHtmlContent ValidationSummary(this IHtmlHelper htmlHelper, string message, string tag)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
message: message,
@ -354,10 +437,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// is valid and client-side validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors,
message,
@ -383,10 +471,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// is valid and client-side validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string message,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
message: message,
@ -415,11 +508,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string message,
object htmlAttributes,
string tag)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors: false,
message: message,
@ -446,11 +544,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message,
string tag)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(
excludePropertyErrors,
message,
@ -479,11 +582,16 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// is valid and client-side validation is disabled).
/// </returns>
public static IHtmlContent ValidationSummary(
[NotNull] this IHtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
bool excludePropertyErrors,
string message,
object htmlAttributes)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.ValidationSummary(excludePropertyErrors, message, htmlAttributes, tag: null);
}
}

View File

@ -3,8 +3,6 @@
using System;
using System.Linq.Expressions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -22,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// Converts the expression result to a <see cref="string"/> directly.
/// </remarks>
public static string Value([NotNull] this IHtmlHelper htmlHelper, string expression)
public static string Value(this IHtmlHelper htmlHelper, string expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Value(expression, format: null);
}
@ -39,9 +42,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Converts the <paramref name="expression"/> result to a <see cref="string"/> directly.
/// </remarks>
public static string ValueFor<TModel, TResult>(
[NotNull] this IHtmlHelper<TModel> htmlHelper,
[NotNull] Expression<Func<TModel, TResult>> expression)
this IHtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TResult>> expression)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return htmlHelper.ValueFor(expression, format: null);
}
@ -53,8 +66,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// Converts the model value to a <see cref="string"/> directly.
/// </remarks>
public static string ValueForModel([NotNull] this IHtmlHelper htmlHelper)
public static string ValueForModel(this IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Value(expression: null, format: null);
}
@ -70,8 +88,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Converts the model value to a <see cref="string"/> directly if
/// <paramref name="format"/> is <c>null</c> or empty.
/// </remarks>
public static string ValueForModel([NotNull] this IHtmlHelper htmlHelper, string format)
public static string ValueForModel(this IHtmlHelper htmlHelper, string format)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return htmlHelper.Value(expression: null, format: format);
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.IO;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.Rendering
@ -36,8 +35,18 @@ namespace Microsoft.AspNet.Mvc.Rendering
}
/// <inheritdoc />
public void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder)
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (encoder == null)
{
throw new ArgumentNullException(nameof(encoder));
}
writer.Write(_input);
}

View File

@ -8,7 +8,6 @@ using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.Rendering
@ -86,7 +85,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
IHtmlContent ActionLink(
[NotNull] string linkText,
string linkText,
string actionName,
string controllerName,
string protocol,
@ -360,7 +359,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Fully-qualified expression name, ignoring the current model. Must not be <c>null</c>.
/// </param>
/// <returns>A <see cref="string"/> containing the element Id.</returns>
string GenerateIdFromName([NotNull] string fullName);
string GenerateIdFromName(string fullName);
/// <summary>
/// Returns information about about client validation rules for the specified <paramref name="metadata"/> or
@ -402,7 +401,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Thrown if <paramref name="enumType"/> is not an <see cref="Enum"/> or if it has a
/// <see cref="FlagsAttribute"/>.
/// </exception>
IEnumerable<SelectListItem> GetEnumSelectList([NotNull] Type enumType);
IEnumerable<SelectListItem> GetEnumSelectList(Type enumType);
/// <summary>
/// Returns an &lt;input&gt; element of type "hidden" for the specified <paramref name="expression"/>.
@ -502,7 +501,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// A <see cref="Task"/> that on completion returns a new <see cref="HtmlString"/> containing
/// the created HTML.
/// </returns>
Task<IHtmlContent> PartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData);
Task<IHtmlContent> PartialAsync(string partialViewName, object model, ViewDataDictionary viewData);
/// <summary>
/// Returns an &lt;input&gt; element of type "password" for the specified <paramref name="expression"/>.
@ -617,7 +616,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <remarks>
/// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
/// </remarks>
Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData);
Task RenderPartialAsync(string partialViewName, object model, ViewDataDictionary viewData);
/// <summary>
/// Returns an anchor (&lt;a&gt;) element that contains a URL path to the specified route.
@ -639,7 +638,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </param>
/// <returns>A new <see cref="IHtmlContent"/> containing the anchor element.</returns>
IHtmlContent RouteLink(
[NotNull] string linkText,
string linkText,
string routeName,
string protocol,
string hostName,

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// if the <see cref="bool"/> values is <c>true</c>; does not include the attribute otherwise.
/// </para>
/// </remarks>
IHtmlContent CheckBoxFor([NotNull] Expression<Func<TModel, bool>> expression, object htmlAttributes);
IHtmlContent CheckBoxFor(Expression<Func<TModel, bool>> expression, object htmlAttributes);
/// <summary>
/// Returns HTML markup for the <paramref name="expression"/>, using a display template, specified HTML field
@ -80,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="expression"/> result.
/// </remarks>
IHtmlContent DisplayFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string templateName,
string htmlFieldName,
object additionalViewData);
@ -91,7 +90,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">An expression to be evaluated against the current model.</param>
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A <see cref="string"/> containing the display name.</returns>
string DisplayNameFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression);
string DisplayNameFor<TResult>(Expression<Func<TModel, TResult>> expression);
/// <summary>
/// Returns the display name for the specified <paramref name="expression"/>
@ -102,7 +101,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A <see cref="string"/> containing the display name.</returns>
string DisplayNameForInnerType<TModelItem, TResult>(
[NotNull] Expression<Func<TModelItem, TResult>> expression);
Expression<Func<TModelItem, TResult>> expression);
/// <summary>
/// Returns the simple display text for the specified <paramref name="expression"/>.
@ -114,7 +113,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// If the <paramref name="expression"/> result is <c>null</c>, returns
/// <see cref="ModelBinding.ModelMetadata.NullDisplayText"/>.
/// </returns>
string DisplayTextFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression);
string DisplayTextFor<TResult>(Expression<Func<TModel, TResult>> expression);
/// <summary>
/// Returns a single-selection HTML &lt;select&gt; element for the <paramref name="expression"/>, using the
@ -140,7 +139,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </remarks>
IHtmlContent DropDownListFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList,
string optionLabel,
object htmlAttributes);
@ -168,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// elements for each property in the <paramref name="expression"/> result.
/// </remarks>
IHtmlContent EditorFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string templateName,
string htmlFieldName,
object additionalViewData);
@ -210,7 +209,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
IHtmlContent HiddenFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
object htmlAttributes);
/// <summary>
@ -219,7 +218,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">An expression to be evaluated against the current model.</param>
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A <see cref="string"/> containing the element Id.</returns>
string IdFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression);
string IdFor<TResult>(Expression<Func<TModel, TResult>> expression);
/// <summary>
/// Returns a &lt;label&gt; element for the specified <paramref name="expression"/>.
@ -233,7 +232,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A new <see cref="IHtmlContent"/> containing the &lt;label&gt; element.</returns>
IHtmlContent LabelFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string labelText,
object htmlAttributes);
@ -258,7 +257,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// representation of the <paramref name="expression"/> to set element's "id" attribute.
/// </remarks>
IHtmlContent ListBoxFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList,
object htmlAttributes);
@ -268,7 +267,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="expression">An expression to be evaluated against the current model.</param>
/// <typeparam name="TResult">The type of the <paramref name="expression"/> result.</typeparam>
/// <returns>A <see cref="string"/> containing the element name.</returns>
string NameFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression);
string NameFor<TResult>(Expression<Func<TModel, TResult>> expression);
/// <summary>
/// Returns an &lt;input&gt; element of type "password" for the specified <paramref name="expression"/>.
@ -297,7 +296,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
IHtmlContent PasswordFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
object htmlAttributes);
/// <summary>
@ -337,8 +336,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </para>
/// </remarks>
IHtmlContent RadioButtonFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
[NotNull] object value,
Expression<Func<TModel, TResult>> expression,
object value,
object htmlAttributes);
/// <inheritdoc cref="IHtmlHelper.Raw(object)"/>
@ -378,7 +377,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
IHtmlContent TextAreaFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
int rows,
int columns,
object htmlAttributes);
@ -418,7 +417,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// </list>
/// </remarks>
IHtmlContent TextBoxFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string format,
object htmlAttributes);
@ -446,7 +445,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="expression"/> is valid and client-side validation is disabled.
/// </returns>
IHtmlContent ValidationMessageFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string message,
object htmlAttributes,
string tag);
@ -465,7 +464,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <paramref name="format"/> is <c>null</c> or empty.
/// </remarks>
string ValueFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string format);
}
}

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc.Rendering
@ -24,6 +23,6 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="value">The value to serialize as JSON.</param>
/// <param name="serializerSettings">The <see cref="JsonSerializerSettings"/> to be used by the serializer.</param>
/// <returns>A new <see cref="HtmlString"/> containing the serialized JSON.</returns>
HtmlString Serialize(object value, [NotNull] JsonSerializerSettings serializerSettings);
HtmlString Serialize(object value, JsonSerializerSettings serializerSettings);
}
}

View File

@ -7,7 +7,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -15,28 +14,44 @@ namespace Microsoft.AspNet.Mvc.Rendering
{
private IList<SelectListGroup> _groups;
public MultiSelectList([NotNull] IEnumerable items)
public MultiSelectList(IEnumerable items)
: this(items, selectedValues: null)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
}
public MultiSelectList([NotNull] IEnumerable items, IEnumerable selectedValues)
public MultiSelectList(IEnumerable items, IEnumerable selectedValues)
: this(items, dataValueField: null, dataTextField: null, selectedValues: selectedValues)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
}
public MultiSelectList([NotNull] IEnumerable items, string dataValueField, string dataTextField)
public MultiSelectList(IEnumerable items, string dataValueField, string dataTextField)
: this(items, dataValueField, dataTextField, selectedValues: null)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
}
public MultiSelectList(
[NotNull] IEnumerable items,
IEnumerable items,
string dataValueField,
string dataTextField,
IEnumerable selectedValues)
: this(items, dataValueField, dataTextField, selectedValues, dataGroupField: null)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
}
/// <summary>
@ -53,12 +68,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="dataGroupField">The data group field. Used to match the Group property of the corresponding
/// <see cref="SelectListItem"/>.</param>
public MultiSelectList(
[NotNull] IEnumerable items,
IEnumerable items,
string dataValueField,
string dataTextField,
IEnumerable selectedValues,
string dataGroupField)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
Items = items;
DataValueField = dataValueField;
DataTextField = dataTextField;

View File

@ -3,7 +3,6 @@
using System;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -12,8 +11,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
private readonly ViewContext _viewContext;
private bool _disposed;
public MvcForm([NotNull] ViewContext viewContext)
public MvcForm(ViewContext viewContext)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
_viewContext = viewContext;
// Push the new FormContext; GenerateEndForm() does the corresponding pop.

View File

@ -1,35 +1,52 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
public class SelectList : MultiSelectList
{
public SelectList([NotNull] IEnumerable items)
public SelectList(IEnumerable items)
: this(items, selectedValue: null)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
}
public SelectList([NotNull] IEnumerable items, object selectedValue)
public SelectList(IEnumerable items, object selectedValue)
: this(items, dataValueField: null, dataTextField: null, selectedValue: selectedValue)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
}
public SelectList([NotNull] IEnumerable items, string dataValueField, string dataTextField)
public SelectList(IEnumerable items, string dataValueField, string dataTextField)
: this(items, dataValueField, dataTextField, selectedValue: null)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
}
public SelectList(
[NotNull] IEnumerable items,
IEnumerable items,
string dataValueField,
string dataTextField,
object selectedValue)
: base(items, dataValueField, dataTextField, ToEnumerable(selectedValue))
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
SelectedValue = selectedValue;
}
@ -47,13 +64,18 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="dataGroupField">The data group field. Used to match the Group property of the corresponding
/// <see cref="SelectListItem"/>.</param>
public SelectList(
[NotNull] IEnumerable items,
IEnumerable items,
string dataValueField,
string dataTextField,
object selectedValue,
string dataGroupField)
: base(items, dataValueField, dataTextField, ToEnumerable(selectedValue), dataGroupField)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
SelectedValue = selectedValue;
}

View File

@ -71,8 +71,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// Valid HTML 4.01 "id" attribute for an element with the given <paramref name="name"/>.
/// </returns>
/// <remarks>Valid "id" attributes are defined in http://www.w3.org/TR/html401/types.html#type-id</remarks>
public static string CreateSanitizedId(string name, [NotNull] string invalidCharReplacement)
public static string CreateSanitizedId(string name, string invalidCharReplacement)
{
if (invalidCharReplacement == null)
{
throw new ArgumentNullException(nameof(invalidCharReplacement));
}
if (string.IsNullOrEmpty(name))
{
return string.Empty;
@ -127,8 +132,13 @@ namespace Microsoft.AspNet.Mvc.Rendering
return stringBuffer.ToString();
}
public void GenerateId(string name, [NotNull] string idAttributeDotReplacement)
public void GenerateId(string name, string idAttributeDotReplacement)
{
if (idAttributeDotReplacement == null)
{
throw new ArgumentNullException(nameof(idAttributeDotReplacement));
}
if (!Attributes.ContainsKey("id"))
{
var sanitizedId = CreateSanitizedId(name, idAttributeDotReplacement);

View File

@ -1,36 +1,54 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewComponents;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
public static class ViewComponentHelperExtensions
{
public static HtmlString Invoke<TComponent>([NotNull] this IViewComponentHelper helper,
public static HtmlString Invoke<TComponent>(this IViewComponentHelper helper,
params object[] args)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.Invoke(typeof(TComponent), args);
}
public static void RenderInvoke<TComponent>([NotNull] this IViewComponentHelper helper,
public static void RenderInvoke<TComponent>(this IViewComponentHelper helper,
params object[] args)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
helper.RenderInvoke(typeof(TComponent), args);
}
public static Task<HtmlString> InvokeAsync<TComponent>([NotNull] this IViewComponentHelper helper,
public static Task<HtmlString> InvokeAsync<TComponent>(this IViewComponentHelper helper,
params object[] args)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.InvokeAsync(typeof(TComponent), args);
}
public static Task RenderInvokeAsync<TComponent>([NotNull] this IViewComponentHelper helper,
public static Task RenderInvokeAsync<TComponent>(this IViewComponentHelper helper,
params object[] args)
{
if (helper == null)
{
throw new ArgumentNullException(nameof(helper));
}
return helper.RenderInvokeAsync(typeof(TComponent), args);
}
}

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -40,14 +40,44 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="tempData">The <see cref="ITempDataDictionary"/>.</param>
/// <param name="writer">The <see cref="TextWriter"/> to render output to.</param>
public ViewContext(
[NotNull] ActionContext actionContext,
[NotNull] IView view,
[NotNull] ViewDataDictionary viewData,
[NotNull] ITempDataDictionary tempData,
[NotNull] TextWriter writer,
[NotNull] HtmlHelperOptions htmlHelperOptions)
ActionContext actionContext,
IView view,
ViewDataDictionary viewData,
ITempDataDictionary tempData,
TextWriter writer,
HtmlHelperOptions htmlHelperOptions)
: base(actionContext)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (view == null)
{
throw new ArgumentNullException(nameof(view));
}
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
if (tempData == null)
{
throw new ArgumentNullException(nameof(tempData));
}
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (htmlHelperOptions == null)
{
throw new ArgumentNullException(nameof(htmlHelperOptions));
}
View = view;
ViewData = viewData;
TempData = tempData;
@ -68,12 +98,32 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="viewData">The <see cref="ViewDataDictionary"/>.</param>
/// <param name="writer">The <see cref="TextWriter"/> to render output to.</param>
public ViewContext(
[NotNull] ViewContext viewContext,
[NotNull] IView view,
[NotNull] ViewDataDictionary viewData,
[NotNull] TextWriter writer)
ViewContext viewContext,
IView view,
ViewDataDictionary viewData,
TextWriter writer)
: base(viewContext)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (view == null)
{
throw new ArgumentNullException(nameof(view));
}
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
_formContext = viewContext.FormContext;
ClientValidationEnabled = viewContext.ClientValidationEnabled;
Html5DateRenderingMode = viewContext.Html5DateRenderingMode;

View File

@ -5,7 +5,6 @@ using System;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc
{
@ -16,13 +15,22 @@ namespace Microsoft.AspNet.Mvc
public class SkipStatusCodePagesAttribute : Attribute, IResourceFilter
{
/// <inheritdoc />
public void OnResourceExecuted([NotNull] ResourceExecutedContext context)
public void OnResourceExecuted(ResourceExecutedContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
}
/// <inheritdoc />
public void OnResourceExecuting([NotNull] ResourceExecutingContext context)
public void OnResourceExecuting(ResourceExecutingContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var statusCodeFeature = context.HttpContext.Features.Get<IStatusCodePagesFeature>();
if (statusCodeFeature != null)
{

View File

@ -1,17 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Security.Principal;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Mvc.ViewComponents;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc
@ -114,10 +113,13 @@ namespace Microsoft.AspNet.Mvc
return _url;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_url = value;
}
}
@ -135,10 +137,13 @@ namespace Microsoft.AspNet.Mvc
return _viewComponentContext;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_viewComponentContext = value;
}
}
@ -181,10 +186,13 @@ namespace Microsoft.AspNet.Mvc
return _viewEngine;
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_viewEngine = value;
}
}
@ -194,8 +202,13 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
/// <param name="content">The content, will be HTML encoded before output.</param>
/// <returns>A <see cref="ContentViewComponentResult"/>.</returns>
public ContentViewComponentResult Content([NotNull] string content)
public ContentViewComponentResult Content(string content)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
return new ContentViewComponentResult(content);
}
@ -218,8 +231,13 @@ namespace Microsoft.AspNet.Mvc
/// <returns>A <see cref="JsonViewComponentResult"/>.</returns>
/// <remarks>Callers should cache an instance of <see cref="JsonSerializerSettings"/> to avoid
/// recreating cached data with each call.</remarks>
public JsonViewComponentResult Json(object value, [NotNull] JsonSerializerSettings serializerSettings)
public JsonViewComponentResult Json(object value, JsonSerializerSettings serializerSettings)
{
if (serializerSettings == null)
{
throw new ArgumentNullException(nameof(serializerSettings));
}
return new JsonViewComponentResult(value, serializerSettings);
}

View File

@ -6,7 +6,6 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewComponents;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Mvc.ViewFeatures.Internal;

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -26,8 +26,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// Initializes a new <see cref="ContentViewComponentResult"/>.
/// </summary>
/// <param name="content">Content to write. The content be HTML encoded when output.</param>
public ContentViewComponentResult([NotNull] string content)
public ContentViewComponentResult(string content)
{
if (content == null)
{
throw new ArgumentNullException(nameof(content));
}
Content = content;
EncodedContent = new HtmlString(WebUtility.HtmlEncode(content));
}
@ -39,8 +44,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// Content to write. The content is treated as already HTML encoded, and no further encoding
/// will be performed.
/// </param>
public ContentViewComponentResult([NotNull] HtmlString encodedContent)
public ContentViewComponentResult(HtmlString encodedContent)
{
if (encodedContent == null)
{
throw new ArgumentNullException(nameof(encodedContent));
}
EncodedContent = encodedContent;
Content = WebUtility.HtmlDecode(encodedContent.ToString());
}
@ -59,8 +69,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// Writes the <see cref="EncodedContent"/>.
/// </summary>
/// <param name="context">The <see cref="ViewComponentContext"/>.</param>
public void Execute([NotNull] ViewComponentContext context)
public void Execute(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.Writer.Write(EncodedContent.ToString());
}
@ -69,8 +84,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// </summary>
/// <param name="context">The <see cref="ViewComponentContext"/>.</param>
/// <returns>A completed <see cref="Task"/>.</returns>
public Task ExecuteAsync([NotNull] ViewComponentContext context)
public Task ExecuteAsync(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return context.Writer.WriteAsync(EncodedContent.ToString());
}
}

View File

@ -35,8 +35,18 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
/// <inheritdoc />
public virtual void Activate([NotNull] object viewComponent, [NotNull] ViewComponentContext context)
public virtual void Activate(object viewComponent, ViewComponentContext context)
{
if (viewComponent == null)
{
throw new ArgumentNullException(nameof(viewComponent));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var propertiesToActivate = _injectActions.GetOrAdd(
viewComponent.GetType(),
_getPropertiesToActivate);

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -53,8 +53,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// <returns>
/// <c>true</c> if <paramref name="typeInfo"/>represents a View Component class, otherwise <c>false</c>.
/// </returns>
protected virtual bool IsViewComponentType([NotNull] TypeInfo typeInfo)
protected virtual bool IsViewComponentType(TypeInfo typeInfo)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
return ViewComponentConventions.IsComponent(typeInfo);
}

View File

@ -7,7 +7,6 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Mvc.ViewFeatures.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -19,22 +18,47 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
private ViewContext _viewContext;
public DefaultViewComponentHelper(
[NotNull] IViewComponentDescriptorCollectionProvider descriptorProvider,
[NotNull] IViewComponentSelector selector,
[NotNull] IViewComponentInvokerFactory invokerFactory)
IViewComponentDescriptorCollectionProvider descriptorProvider,
IViewComponentSelector selector,
IViewComponentInvokerFactory invokerFactory)
{
if (descriptorProvider == null)
{
throw new ArgumentNullException(nameof(descriptorProvider));
}
if (selector == null)
{
throw new ArgumentNullException(nameof(selector));
}
if (invokerFactory == null)
{
throw new ArgumentNullException(nameof(invokerFactory));
}
_descriptorProvider = descriptorProvider;
_selector = selector;
_invokerFactory = invokerFactory;
}
public void Contextualize([NotNull] ViewContext viewContext)
public void Contextualize(ViewContext viewContext)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
_viewContext = viewContext;
}
public HtmlString Invoke([NotNull] string name, params object[] arguments)
public HtmlString Invoke(string name, params object[] arguments)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
var descriptor = SelectComponent(name);
using (var writer = new StringWriter())
@ -44,8 +68,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
}
public HtmlString Invoke([NotNull] Type componentType, params object[] arguments)
public HtmlString Invoke(Type componentType, params object[] arguments)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var descriptor = SelectComponent(componentType);
using (var writer = new StringWriter())
@ -55,20 +84,35 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
}
public void RenderInvoke([NotNull] string name, params object[] arguments)
public void RenderInvoke(string name, params object[] arguments)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
var descriptor = SelectComponent(name);
InvokeCore(_viewContext.Writer, descriptor, arguments);
}
public void RenderInvoke([NotNull] Type componentType, params object[] arguments)
public void RenderInvoke(Type componentType, params object[] arguments)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var descriptor = SelectComponent(componentType);
InvokeCore(_viewContext.Writer, descriptor, arguments);
}
public async Task<HtmlString> InvokeAsync([NotNull] string name, params object[] arguments)
public async Task<HtmlString> InvokeAsync(string name, params object[] arguments)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
var descriptor = SelectComponent(name);
using (var writer = new StringWriter())
@ -78,8 +122,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
}
public async Task<HtmlString> InvokeAsync([NotNull] Type componentType, params object[] arguments)
public async Task<HtmlString> InvokeAsync(Type componentType, params object[] arguments)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var descriptor = SelectComponent(componentType);
using (var writer = new StringWriter())
@ -89,14 +138,24 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
}
public Task RenderInvokeAsync([NotNull] string name, params object[] arguments)
public Task RenderInvokeAsync(string name, params object[] arguments)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
var descriptor = SelectComponent(name);
return InvokeCoreAsync(_viewContext.Writer, descriptor, arguments);
}
public Task RenderInvokeAsync([NotNull] Type componentType, params object[] arguments)
public Task RenderInvokeAsync(Type componentType, params object[] arguments)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var descriptor = SelectComponent(componentType);
return InvokeCoreAsync(_viewContext.Writer, descriptor, arguments);
}
@ -128,10 +187,20 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
private Task InvokeCoreAsync(
[NotNull] TextWriter writer,
[NotNull] ViewComponentDescriptor descriptor,
TextWriter writer,
ViewComponentDescriptor descriptor,
object[] arguments)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
var context = new ViewComponentContext(descriptor, arguments, _viewContext, writer);
var invoker = _invokerFactory.CreateInstance(context);
@ -145,10 +214,20 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
private void InvokeCore(
[NotNull] TextWriter writer,
[NotNull] ViewComponentDescriptor descriptor,
TextWriter writer,
ViewComponentDescriptor descriptor,
object[] arguments)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
var context = new ViewComponentContext(descriptor, arguments, _viewContext, writer);
var invoker = _invokerFactory.CreateInstance(context);

View File

@ -9,7 +9,6 @@ using Microsoft.AspNet.Mvc.Controllers;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -19,15 +18,30 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
private readonly IViewComponentActivator _viewComponentActivator;
public DefaultViewComponentInvoker(
[NotNull] ITypeActivatorCache typeActivatorCache,
[NotNull] IViewComponentActivator viewComponentActivator)
ITypeActivatorCache typeActivatorCache,
IViewComponentActivator viewComponentActivator)
{
if (typeActivatorCache == null)
{
throw new ArgumentNullException(nameof(typeActivatorCache));
}
if (viewComponentActivator == null)
{
throw new ArgumentNullException(nameof(viewComponentActivator));
}
_typeActivatorCache = typeActivatorCache;
_viewComponentActivator = viewComponentActivator;
}
public void Invoke([NotNull] ViewComponentContext context)
public void Invoke(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var method = ViewComponentMethodSelector.FindSyncMethod(
context.ViewComponentDescriptor.Type.GetTypeInfo(),
context.Arguments);
@ -41,8 +55,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
result.Execute(context);
}
public async Task InvokeAsync([NotNull] ViewComponentContext context)
public async Task InvokeAsync(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
IViewComponentResult result;
var asyncMethod = ViewComponentMethodSelector.FindAsyncMethod(
@ -74,20 +93,35 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
await result.ExecuteAsync(context);
}
private object CreateComponent([NotNull] ViewComponentContext context)
private object CreateComponent(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var services = context.ViewContext.HttpContext.RequestServices;
var component = _typeActivatorCache.CreateInstance<object>(
services,
services,
context.ViewComponentDescriptor.Type);
_viewComponentActivator.Activate(component, context);
return component;
}
private async Task<IViewComponentResult> InvokeAsyncCore(
[NotNull] MethodInfo method,
[NotNull] ViewComponentContext context)
MethodInfo method,
ViewComponentContext context)
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var component = CreateComponent(context);
var result = await ControllerActionExecutor.ExecuteAsync(method, component, context.Arguments);
@ -95,8 +129,18 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
return CoerceToViewComponentResult(result);
}
public IViewComponentResult InvokeSyncCore([NotNull] MethodInfo method, [NotNull] ViewComponentContext context)
public IViewComponentResult InvokeSyncCore(MethodInfo method, ViewComponentContext context)
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var component = CreateComponent(context);
object result = null;

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -23,8 +23,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
// We don't currently make use of the descriptor or the arguments here (they are available on the context).
// We might do this some day to cache which method we select, so resist the urge to 'clean' this without
// considering that possibility.
public IViewComponentInvoker CreateInstance([NotNull] ViewComponentContext context)
public IViewComponentInvoker CreateInstance(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return new DefaultViewComponentInvoker(
_typeActivatorCache,
_viewComponentActivator);

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -28,8 +27,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
/// <inheritdoc />
public ViewComponentDescriptor SelectComponent([NotNull] string componentName)
public ViewComponentDescriptor SelectComponent(string componentName)
{
if (componentName == null)
{
throw new ArgumentNullException(nameof(componentName));
}
var collection = _descriptorProvider.ViewComponents;
if (_cache == null || _cache.Version != collection.Version)
{

View File

@ -2,14 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
public interface IViewComponentInvoker
{
void Invoke([NotNull] ViewComponentContext context);
void Invoke(ViewComponentContext context);
Task InvokeAsync([NotNull] ViewComponentContext context);
Task InvokeAsync(ViewComponentContext context);
}
}

View File

@ -1,12 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
public interface IViewComponentInvokerFactory
{
IViewComponentInvoker CreateInstance([NotNull] ViewComponentContext context);
IViewComponentInvoker CreateInstance(ViewComponentContext context);
}
}

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
/// <summary>
@ -15,6 +13,6 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// </summary>
/// <param name="componentName">The View Component name.</param>
/// <returns>A <see cref="ViewComponentDescriptor"/>, or <c>null</c> if no match is found.</returns>
ViewComponentDescriptor SelectComponent([NotNull] string componentName);
ViewComponentDescriptor SelectComponent(string componentName);
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
using Newtonsoft.Json;
@ -31,8 +31,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// <param name="value">The value to format as JSON text.</param>
/// <param name="serializerSettings">The <see cref="JsonSerializerSettings"/> to be used by
/// the formatter.</param>
public JsonViewComponentResult(object value, [NotNull] JsonSerializerSettings serializerSettings)
public JsonViewComponentResult(object value, JsonSerializerSettings serializerSettings)
{
if (serializerSettings == null)
{
throw new ArgumentNullException(nameof(serializerSettings));
}
Value = value;
_serializerSettings = serializerSettings;
}
@ -46,8 +51,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// Renders JSON text to the output.
/// </summary>
/// <param name="context">The <see cref="ViewComponentContext"/>.</param>
public void Execute([NotNull] ViewComponentContext context)
public void Execute(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var serializerSettings = _serializerSettings;
if (serializerSettings == null)
{
@ -73,8 +83,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// </summary>
/// <param name="context">The <see cref="ViewComponentContext"/>.</param>
/// <returns>A completed <see cref="Task"/>.</returns>
public Task ExecuteAsync([NotNull] ViewComponentContext context)
public Task ExecuteAsync(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
Execute(context);
return Task.FromResult(true);
}

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -36,11 +36,31 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// <param name="viewContext">The <see cref="ViewContext"/>.</param>
/// <param name="writer">The <see cref="TextWriter"/> for writing output.</param>
public ViewComponentContext(
[NotNull] ViewComponentDescriptor viewComponentDescriptor,
[NotNull] object[] arguments,
[NotNull] ViewContext viewContext,
[NotNull] TextWriter writer)
ViewComponentDescriptor viewComponentDescriptor,
object[] arguments,
ViewContext viewContext,
TextWriter writer)
{
if (viewComponentDescriptor == null)
{
throw new ArgumentNullException(nameof(viewComponentDescriptor));
}
if (arguments == null)
{
throw new ArgumentNullException(nameof(arguments));
}
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
ViewComponentDescriptor = viewComponentDescriptor;
Arguments = arguments;
@ -48,7 +68,7 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
// aren't visible in the calling view.
ViewContext = new ViewContext(
viewContext,
viewContext.View,
viewContext.View,
new ViewDataDictionary(viewContext.ViewData),
writer);
}

View File

@ -3,7 +3,6 @@
using System;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -11,8 +10,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
{
private const string ViewComponentSuffix = "ViewComponent";
public static string GetComponentName([NotNull] TypeInfo componentType)
public static string GetComponentName(TypeInfo componentType)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var attribute = componentType.GetCustomAttribute<ViewComponentAttribute>();
if (attribute != null && !string.IsNullOrEmpty(attribute.Name))
{
@ -30,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
return GetShortNameByConvention(componentType);
}
public static string GetComponentFullName([NotNull] TypeInfo componentType)
public static string GetComponentFullName(TypeInfo componentType)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var attribute = componentType.GetCustomAttribute<ViewComponentAttribute>();
if (!string.IsNullOrEmpty(attribute?.Name))
{
@ -63,8 +72,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
}
public static bool IsComponent([NotNull] TypeInfo typeInfo)
public static bool IsComponent(TypeInfo typeInfo)
{
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (!typeInfo.IsClass ||
!typeInfo.IsPublic ||
typeInfo.IsAbstract ||

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// </summary>
/// <param name="items">The result of view component discovery</param>
/// <param name="version">The unique version of discovered view components.</param>
public ViewComponentDescriptorCollection([NotNull] IEnumerable<ViewComponentDescriptor> items, int version)
public ViewComponentDescriptorCollection(IEnumerable<ViewComponentDescriptor> items, int version)
{
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
Items = new List<ViewComponentDescriptor>(items);
Version = version;
}

View File

@ -6,7 +6,6 @@ using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -15,8 +14,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
public const string AsyncMethodName = "InvokeAsync";
public const string SyncMethodName = "Invoke";
public static MethodInfo FindAsyncMethod([NotNull] TypeInfo componentType, object[] args)
public static MethodInfo FindAsyncMethod(TypeInfo componentType, object[] args)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var method = GetMethod(componentType, args, AsyncMethodName);
if (method == null)
{
@ -33,8 +37,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
return method;
}
public static MethodInfo FindSyncMethod([NotNull] TypeInfo componentType, object[] args)
public static MethodInfo FindSyncMethod(TypeInfo componentType, object[] args)
{
if (componentType == null)
{
throw new ArgumentNullException(nameof(componentType));
}
var method = GetMethod(componentType, args, SyncMethodName);
if (method == null)
{

View File

@ -8,7 +8,6 @@ using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
@ -49,8 +48,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// <remarks>
/// This method synchronously calls and blocks on <see cref="ExecuteAsync(ViewComponentContext)"/>.
/// </remarks>
public void Execute([NotNull] ViewComponentContext context)
public void Execute(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var task = ExecuteAsync(context);
task.GetAwaiter().GetResult();
}
@ -61,8 +65,13 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
/// </summary>
/// <param name="context">The <see cref="ViewComponentContext"/> for the current component execution.</param>
/// <returns>A <see cref="Task"/> which will complete when view rendering is completed.</returns>
public async Task ExecuteAsync([NotNull] ViewComponentContext context)
public async Task ExecuteAsync(ViewComponentContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var viewEngine = ViewEngine ?? ResolveViewEngine(context);
var viewData = ViewData ?? context.ViewData;
var isNullOrEmptyViewName = string.IsNullOrEmpty(ViewName);

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.ViewEngines
@ -25,17 +25,37 @@ namespace Microsoft.AspNet.Mvc.ViewEngines
/// <inheritdoc />
public ViewEngineResult FindPartialView(
[NotNull] ActionContext context,
[NotNull] string partialViewName)
ActionContext context,
string partialViewName)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return FindView(context, partialViewName, partial: true);
}
/// <inheritdoc />
public ViewEngineResult FindView(
[NotNull] ActionContext context,
[NotNull] string viewName)
ActionContext context,
string viewName)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (viewName == null)
{
throw new ArgumentNullException(nameof(viewName));
}
return FindView(context, viewName, partial: false);
}

View File

@ -3,7 +3,6 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewEngines
{
@ -22,6 +21,6 @@ namespace Microsoft.AspNet.Mvc.ViewEngines
/// </summary>
/// <param name="context">The <see cref="ViewContext"/>.</param>
/// <returns>A <see cref="Task"/> that on completion renders the view.</returns>
Task RenderAsync([NotNull] ViewContext context);
Task RenderAsync(ViewContext context);
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewEngines
{
@ -26,9 +25,19 @@ namespace Microsoft.AspNet.Mvc.ViewEngines
}
public static ViewEngineResult NotFound(
[NotNull] string viewName,
[NotNull] IEnumerable<string> searchedLocations)
string viewName,
IEnumerable<string> searchedLocations)
{
if (viewName == null)
{
throw new ArgumentNullException(nameof(viewName));
}
if (searchedLocations == null)
{
throw new ArgumentNullException(nameof(searchedLocations));
}
return new ViewEngineResult
{
SearchedLocations = searchedLocations,
@ -36,8 +45,18 @@ namespace Microsoft.AspNet.Mvc.ViewEngines
};
}
public static ViewEngineResult Found([NotNull] string viewName, [NotNull] IView view)
public static ViewEngineResult Found(string viewName, IView view)
{
if (viewName == null)
{
throw new ArgumentNullException(nameof(viewName));
}
if (view == null)
{
throw new ArgumentNullException(nameof(view));
}
return new ViewEngineResult
{
View = view,

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Concurrent;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
// If the provided expression is particularly obscure and the system doesn't know
// how to handle it, we'll just compile the expression as normal.
public static Func<TModel, TResult> Process<TModel, TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression)
Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return Compiler<TModel, TResult>.Compile(expression);
}
@ -32,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
private static readonly ConcurrentDictionary<MemberInfo, Func<object, TResult>> _constMemberAccessCache =
new ConcurrentDictionary<MemberInfo, Func<object, TResult>>();
public static Func<TModel, TResult> Compile([NotNull] Expression<Func<TModel, TResult>> expression)
public static Func<TModel, TResult> Compile(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return CompileFromIdentityFunc(expression)
?? CompileFromConstLookup(expression)
?? CompileFromMemberAccess(expression)
@ -41,8 +50,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
private static Func<TModel, TResult> CompileFromConstLookup(
[NotNull] Expression<Func<TModel, TResult>> expression)
Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var constantExpression = expression.Body as ConstantExpression;
if (constantExpression != null)
{
@ -56,8 +70,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
private static Func<TModel, TResult> CompileFromIdentityFunc(
[NotNull] Expression<Func<TModel, TResult>> expression)
Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
if (expression.Body == expression.Parameters[0])
{
// model => model
@ -75,8 +94,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
private static Func<TModel, TResult> CompileFromMemberAccess(
[NotNull] Expression<Func<TModel, TResult>> expression)
Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
// Performance tests show that on the x64 platform, special-casing static member and
// captured local variable accesses is faster than letting the fingerprinting system
// handle them. On the x86 platform, the fingerprinting system is faster, but only
@ -118,8 +142,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return null;
}
private static Func<TModel, TResult> CompileSlow([NotNull] Expression<Func<TModel, TResult>> expression)
private static Func<TModel, TResult> CompileSlow(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
// fallback compilation system - just compile the expression directly
return expression.Compile();
}

View File

@ -280,7 +280,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var valueDivTag = new TagBuilder("div");
valueDivTag.AddCssClass("editor-field");
valueDivTag.InnerHtml.Append(templateBuilderResult);
valueDivTag.InnerHtml.AppendEncoded(" ");
valueDivTag.InnerHtml.Append(htmlHelper.ValidationMessage(
@ -365,13 +365,23 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return GenerateTextBox(htmlHelper, inputType: "number");
}
public static IHtmlContent FileInputTemplate([NotNull] IHtmlHelper htmlHelper)
public static IHtmlContent FileInputTemplate(IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
return GenerateTextBox(htmlHelper, inputType: "file");
}
public static IHtmlContent FileCollectionInputTemplate([NotNull] IHtmlHelper htmlHelper)
public static IHtmlContent FileCollectionInputTemplate(IHtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException(nameof(htmlHelper));
}
var htmlAttributes =
CreateHtmlAttributes(htmlHelper, className: "text-box single-line", inputType: "file");
htmlAttributes["multiple"] = "multiple";

View File

@ -13,7 +13,6 @@ using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Mvc.ViewFeatures.Internal;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
@ -43,12 +42,37 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <param name="urlHelper">The <see cref="IUrlHelper"/>.</param>
/// <param name="htmlEncoder">The <see cref="IHtmlEncoder"/>.</param>
public DefaultHtmlGenerator(
[NotNull] IAntiforgery antiforgery,
[NotNull] IOptions<MvcViewOptions> optionsAccessor,
[NotNull] IModelMetadataProvider metadataProvider,
[NotNull] IUrlHelper urlHelper,
[NotNull] IHtmlEncoder htmlEncoder)
IAntiforgery antiforgery,
IOptions<MvcViewOptions> optionsAccessor,
IModelMetadataProvider metadataProvider,
IUrlHelper urlHelper,
IHtmlEncoder htmlEncoder)
{
if (antiforgery == null)
{
throw new ArgumentNullException(nameof(antiforgery));
}
if (optionsAccessor == null)
{
throw new ArgumentNullException(nameof(optionsAccessor));
}
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (urlHelper == null)
{
throw new ArgumentNullException(nameof(urlHelper));
}
if (htmlEncoder == null)
{
throw new ArgumentNullException(nameof(htmlEncoder));
}
_antiforgery = antiforgery;
var clientValidatorProviders = optionsAccessor.Value.ClientModelValidatorProviders;
_clientModelValidatorProvider = new CompositeClientModelValidatorProvider(clientValidatorProviders);
@ -83,7 +107,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateActionLink(
[NotNull] string linkText,
string linkText,
string actionName,
string controllerName,
string protocol,
@ -92,25 +116,40 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object routeValues,
object htmlAttributes)
{
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
var url = _urlHelper.Action(actionName, controllerName, routeValues, protocol, hostname, fragment);
return GenerateLink(linkText, url, htmlAttributes);
}
/// <inheritdoc />
public virtual IHtmlContent GenerateAntiforgery([NotNull] ViewContext viewContext)
public virtual IHtmlContent GenerateAntiforgery(ViewContext viewContext)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var tag = _antiforgery.GetHtml(viewContext.HttpContext);
return new HtmlString(tag);
}
/// <inheritdoc />
public virtual TagBuilder GenerateCheckBox(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
bool? isChecked,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (modelExplorer != null)
{
// CheckBoxFor() case. That API does not support passing isChecked directly.
@ -150,10 +189,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateHiddenForCheckbox(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var tagBuilder = new TagBuilder("input");
tagBuilder.MergeAttribute("type", GetInputTypeString(InputType.Hidden));
tagBuilder.MergeAttribute("value", "false");
@ -167,13 +211,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateForm(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string actionName,
string controllerName,
object routeValues,
string method,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var defaultMethod = false;
if (string.IsNullOrEmpty(method))
{
@ -203,12 +252,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public TagBuilder GenerateRouteForm(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string routeName,
object routeValues,
string method,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var action =
_urlHelper.RouteUrl(routeName, values: routeValues, protocol: null, host: null, fragment: null);
@ -217,13 +271,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateHidden(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
bool useViewData,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
// Special-case opaque values and arbitrary binary data.
var byteArrayValue = value as byte[];
if (byteArrayValue != null)
@ -248,12 +307,22 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateLabel(
[NotNull] ViewContext viewContext,
[NotNull] ModelExplorer modelExplorer,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
string labelText,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (modelExplorer == null)
{
throw new ArgumentNullException(nameof(modelExplorer));
}
var resolvedLabelText = labelText ??
modelExplorer.Metadata.DisplayName ??
modelExplorer.Metadata.PropertyName;
@ -280,12 +349,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GeneratePassword(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var htmlAttributeDictionary = GetHtmlAttributeDictionaryOrNull(htmlAttributes);
return GenerateInput(
viewContext,
@ -303,13 +377,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateRadioButton(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
bool? isChecked,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var htmlAttributeDictionary = GetHtmlAttributeDictionaryOrNull(htmlAttributes);
if (modelExplorer == null)
{
@ -367,7 +446,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateRouteLink(
[NotNull] string linkText,
string linkText,
string routeName,
string protocol,
string hostName,
@ -375,13 +454,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object routeValues,
object htmlAttributes)
{
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
var url = _urlHelper.RouteUrl(routeName, routeValues, protocol, hostName, fragment);
return GenerateLink(linkText, url, htmlAttributes);
}
/// <inheritdoc />
public TagBuilder GenerateSelect(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string optionLabel,
string expression,
@ -389,6 +473,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
bool allowMultiple,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var currentValues = GetCurrentValues(viewContext, modelExplorer, expression, allowMultiple);
return GenerateSelect(
viewContext,
@ -403,7 +492,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateSelect(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string optionLabel,
string expression,
@ -412,6 +501,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
bool allowMultiple,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var fullName = GetFullHtmlFieldName(viewContext, expression);
if (string.IsNullOrEmpty(fullName))
{
@ -423,7 +517,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
nameof(IHtmlHelper<object>.EditorFor),
"htmlFieldName"),
nameof(expression));
}
}
// If we got a null selectList, try to use ViewData to get the list of items.
if (selectList == null)
@ -468,13 +562,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateTextArea(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
int rows,
int columns,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (rows < 0)
{
throw new ArgumentOutOfRangeException(nameof(rows), Resources.HtmlHelper_TextAreaParameterOutOfRange);
@ -545,13 +644,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateTextBox(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
string format,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var htmlAttributeDictionary = GetHtmlAttributeDictionaryOrNull(htmlAttributes);
return GenerateInput(
viewContext,
@ -569,12 +673,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateValidationMessage(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string expression,
string message,
string tag,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var fullName = GetFullHtmlFieldName(viewContext, expression);
if (string.IsNullOrEmpty(fullName))
{
@ -649,12 +758,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual TagBuilder GenerateValidationSummary(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
bool excludePropertyErrors,
string message,
string headerTag,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var formContext = viewContext.ClientValidationEnabled ? viewContext.FormContext : null;
if (viewContext.ViewData.ModelState.IsValid && (formContext == null || excludePropertyErrors))
{
@ -717,7 +831,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
{
tagBuilder.AddCssClass(HtmlHelper.ValidationSummaryCssClassName);
}
tagBuilder.InnerHtml.Append(wrappedMessage);
tagBuilder.InnerHtml.Append(htmlSummary);
@ -732,10 +846,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
modelExplorer = modelExplorer ??
ExpressionMetadataProvider.FromStringExpression(expression, viewContext.ViewData, _metadataProvider);
var validationContext = new ClientModelValidationContext(
@ -752,11 +871,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public virtual IReadOnlyCollection<string> GetCurrentValues(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
bool allowMultiple)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var fullName = GetFullHtmlFieldName(viewContext, expression);
if (string.IsNullOrEmpty(fullName))
{
@ -953,11 +1077,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// A <see cref="TagBuilder"/> instance for the &lt;/form&gt; element.
/// </returns>
protected virtual TagBuilder GenerateFormCore(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string action,
string method,
object htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
var tagBuilder = new TagBuilder("form");
tagBuilder.MergeAttributes(GetHtmlAttributeDictionaryOrNull(htmlAttributes));
@ -978,7 +1107,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
protected virtual TagBuilder GenerateInput(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
InputType inputType,
ModelExplorer modelExplorer,
string expression,
@ -990,6 +1119,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
string format,
IDictionary<string, object> htmlAttributes)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
// Not valid to use TextBoxForModel() and so on in a top-level view; would end up with an unnamed input
// elements. But we support the *ForModel() methods in any lower-level template, once HtmlFieldPrefix is
// non-empty.
@ -1104,10 +1238,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
protected virtual TagBuilder GenerateLink(
[NotNull] string linkText,
[NotNull] string url,
string linkText,
string url,
object htmlAttributes)
{
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
var tagBuilder = new TagBuilder("a");
tagBuilder.InnerHtml.SetContent(linkText);
@ -1215,9 +1354,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
private static IEnumerable<SelectListItem> GetSelectListItems(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string expression)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
// Method is called only if user did not pass a select list in. They must provide select list items in the
// ViewData dictionary and definitely not as the Model. (Even if the Model datatype were correct, a
// <select> element generated for a collection of SelectListItems would be useless.)
@ -1311,7 +1455,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
{
groupBuilder.InnerHtml.AppendLine(GenerateOption(item));
}
listItemBuilder.AppendLine(groupBuilder);
}
else

View File

@ -4,8 +4,6 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -13,8 +11,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
{
private readonly Func<ViewDataDictionary> _viewDataFunc;
public DynamicViewData([NotNull] Func<ViewDataDictionary> viewDataFunc)
public DynamicViewData(Func<ViewDataDictionary> viewDataFunc)
{
if (viewDataFunc == null)
{
throw new ArgumentNullException(nameof(viewDataFunc));
}
_viewDataFunc = viewDataFunc;
}
@ -40,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return ViewData.Keys;
}
public override bool TryGetMember([NotNull] GetMemberBinder binder, out object result)
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (binder == null)
{
throw new ArgumentNullException(nameof(binder));
}
result = ViewData[binder.Name];
// ViewDataDictionary[key] will never throw a KeyNotFoundException.
@ -49,8 +57,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return true;
}
public override bool TrySetMember([NotNull] SetMemberBinder binder, object value)
public override bool TrySetMember(SetMemberBinder binder, object value)
{
if (binder == null)
{
throw new ArgumentNullException(nameof(binder));
}
ViewData[binder.Name] = value;
// Can always add / update a ViewDataDictionary value.

View File

@ -7,7 +7,6 @@ using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return string.Equals(expression, "model", StringComparison.OrdinalIgnoreCase) ? string.Empty : expression;
}
public static string GetExpressionText([NotNull] LambdaExpression expression)
public static string GetExpressionText(LambdaExpression expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
// Split apart the expression string for property/field accessors to create its name
var nameParts = new Stack<string>();
var part = expression.Body;
@ -104,9 +108,19 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
private static string GetIndexerInvocation(
[NotNull] Expression expression,
[NotNull] ParameterExpression[] parameters)
Expression expression,
ParameterExpression[] parameters)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
if (parameters == null)
{
throw new ArgumentNullException(nameof(parameters));
}
var converted = Expression.Convert(expression, typeof(object));
var fakeParameter = Expression.Parameter(typeof(object), null);
var lambda = Expression.Lambda<Func<object, object>>(converted, fakeParameter);

View File

@ -6,18 +6,26 @@ using System.Globalization;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
public static class ExpressionMetadataProvider
{
public static ModelExplorer FromLambdaExpression<TModel, TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
[NotNull] ViewDataDictionary<TModel> viewData,
Expression<Func<TModel, TResult>> expression,
ViewDataDictionary<TModel> viewData,
IModelMetadataProvider metadataProvider)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
string propertyName = null;
Type containerType = null;
var legalExpression = false;
@ -103,9 +111,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </returns>
public static ModelExplorer FromStringExpression(
string expression,
[NotNull] ViewDataDictionary viewData,
ViewDataDictionary viewData,
IModelMetadataProvider metadataProvider)
{
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
var viewDataInfo = ViewDataEvaluator.Eval(viewData, expression);
if (viewDataInfo == null)
{
@ -160,9 +173,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
private static ModelExplorer FromModel(
[NotNull] ViewDataDictionary viewData,
ViewDataDictionary viewData,
IModelMetadataProvider metadataProvider)
{
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
if (viewData.ModelMetadata.ModelType == typeof(object))
{
// Use common simple type rather than object so e.g. Editor() at least generates a TextBox.

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -30,16 +29,26 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
}
public bool RenderedField([NotNull] string fieldName)
public bool RenderedField(string fieldName)
{
if (fieldName == null)
{
throw new ArgumentNullException(nameof(fieldName));
}
bool result;
_renderedFields.TryGetValue(fieldName, out result);
return result;
}
public void RenderedField([NotNull] string fieldName, bool value)
public void RenderedField(string fieldName, bool value)
{
if (fieldName == null)
{
throw new ArgumentNullException(nameof(fieldName));
}
_renderedFields[fieldName] = value;
}
}

View File

@ -40,13 +40,43 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// Initializes a new instance of the <see cref="HtmlHelper"/> class.
/// </summary>
public HtmlHelper(
[NotNull] IHtmlGenerator htmlGenerator,
[NotNull] ICompositeViewEngine viewEngine,
[NotNull] IModelMetadataProvider metadataProvider,
[NotNull] IHtmlEncoder htmlEncoder,
[NotNull] IUrlEncoder urlEncoder,
[NotNull] IJavaScriptStringEncoder javaScriptStringEncoder)
IHtmlGenerator htmlGenerator,
ICompositeViewEngine viewEngine,
IModelMetadataProvider metadataProvider,
IHtmlEncoder htmlEncoder,
IUrlEncoder urlEncoder,
IJavaScriptStringEncoder javaScriptStringEncoder)
{
if (htmlGenerator == null)
{
throw new ArgumentNullException(nameof(htmlGenerator));
}
if (viewEngine == null)
{
throw new ArgumentNullException(nameof(viewEngine));
}
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (htmlEncoder == null)
{
throw new ArgumentNullException(nameof(htmlEncoder));
}
if (urlEncoder == null)
{
throw new ArgumentNullException(nameof(urlEncoder));
}
if (javaScriptStringEncoder == null)
{
throw new ArgumentNullException(nameof(javaScriptStringEncoder));
}
_viewEngine = viewEngine;
_htmlGenerator = htmlGenerator;
_htmlEncoder = htmlEncoder;
@ -184,14 +214,19 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return dictionary;
}
public virtual void Contextualize([NotNull] ViewContext viewContext)
public virtual void Contextualize(ViewContext viewContext)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
ViewContext = viewContext;
}
/// <inheritdoc />
public IHtmlContent ActionLink(
[NotNull] string linkText,
string linkText,
string actionName,
string controllerName,
string protocol,
@ -200,6 +235,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object routeValues,
object htmlAttributes)
{
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
var tagBuilder = _htmlGenerator.GenerateActionLink(
linkText,
actionName,
@ -277,8 +317,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public string GenerateIdFromName([NotNull] string fullName)
public string GenerateIdFromName(string fullName)
{
if (fullName == null)
{
throw new ArgumentNullException(nameof(fullName));
}
return TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement);
}
@ -360,8 +405,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public IEnumerable<SelectListItem> GetEnumSelectList([NotNull] Type enumType)
public IEnumerable<SelectListItem> GetEnumSelectList(Type enumType)
{
if (enumType == null)
{
throw new ArgumentNullException(nameof(enumType));
}
var metadata = MetadataProvider.GetMetadataForType(enumType);
if (!metadata.IsEnum || metadata.IsFlagsEnum)
{
@ -421,10 +471,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public async Task<IHtmlContent> PartialAsync(
[NotNull] string partialViewName,
string partialViewName,
object model,
ViewDataDictionary viewData)
{
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
using (var writer = new StringCollectionTextWriter(Encoding.UTF8))
{
await RenderPartialCoreAsync(partialViewName, model, viewData, writer);
@ -433,8 +488,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData)
public Task RenderPartialAsync(string partialViewName, object model, ViewDataDictionary viewData)
{
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
return RenderPartialCoreAsync(partialViewName, model, viewData, ViewContext.Writer);
}
@ -455,11 +515,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return templateBuilder.Build();
}
protected virtual async Task RenderPartialCoreAsync([NotNull] string partialViewName,
protected virtual async Task RenderPartialCoreAsync(string partialViewName,
object model,
ViewDataDictionary viewData,
TextWriter writer)
{
if (partialViewName == null)
{
throw new ArgumentNullException(nameof(partialViewName));
}
// Determine which ViewData we should use to construct a new ViewData
var baseViewData = viewData ?? ViewData;
@ -522,7 +587,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent RouteLink(
[NotNull] string linkText,
string linkText,
string routeName,
string protocol,
string hostName,
@ -530,6 +595,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object routeValues,
object htmlAttributes)
{
if (linkText == null)
{
throw new ArgumentNullException(nameof(linkText));
}
var tagBuilder = _htmlGenerator.GenerateRouteLink(
linkText,
routeName,
@ -647,8 +717,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return new BufferedHtmlContent().Append(checkbox).Append(hidden);
}
protected virtual string GenerateDisplayName([NotNull] ModelExplorer modelExplorer, string expression)
protected virtual string GenerateDisplayName(ModelExplorer modelExplorer, string expression)
{
if (modelExplorer == null)
{
throw new ArgumentNullException(nameof(modelExplorer));
}
// We don't call ModelMetadata.GetDisplayName here because
// we want to fall back to the field name rather than the ModelType.
// This is similar to how the GenerateLabel get the text of a label.
@ -852,11 +927,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
protected virtual IHtmlContent GenerateLabel(
[NotNull] ModelExplorer modelExplorer,
ModelExplorer modelExplorer,
string expression,
string labelText,
object htmlAttributes)
{
if (modelExplorer == null)
{
throw new ArgumentNullException(nameof(modelExplorer));
}
var tagBuilder = _htmlGenerator.GenerateLabel(
ViewContext,
modelExplorer,
@ -1071,8 +1151,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// Thrown if <paramref name="metadata"/>'s <see cref="ModelMetadata.ModelType"/> is not an <see cref="Enum"/>
/// or if it has a <see cref="FlagsAttribute"/>.
/// </exception>
protected virtual IEnumerable<SelectListItem> GetEnumSelectList([NotNull] ModelMetadata metadata)
protected virtual IEnumerable<SelectListItem> GetEnumSelectList(ModelMetadata metadata)
{
if (metadata == null)
{
throw new ArgumentNullException(nameof(metadata));
}
if (!metadata.IsEnum || metadata.IsFlagsEnum)
{
var message = Resources.FormatHtmlHelper_TypeNotSupported_ForGetEnumSelectList(

View File

@ -8,7 +8,6 @@ using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.ViewFeatures
@ -19,21 +18,50 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// Initializes a new instance of the <see cref="HtmlHelper{TModel}"/> class.
/// </summary>
public HtmlHelper(
[NotNull] IHtmlGenerator htmlGenerator,
[NotNull] ICompositeViewEngine viewEngine,
[NotNull] IModelMetadataProvider metadataProvider,
[NotNull] IHtmlEncoder htmlEncoder,
[NotNull] IUrlEncoder urlEncoder,
[NotNull] IJavaScriptStringEncoder javaScriptStringEncoder)
IHtmlGenerator htmlGenerator,
ICompositeViewEngine viewEngine,
IModelMetadataProvider metadataProvider,
IHtmlEncoder htmlEncoder,
IUrlEncoder urlEncoder,
IJavaScriptStringEncoder javaScriptStringEncoder)
: base(htmlGenerator, viewEngine, metadataProvider, htmlEncoder, urlEncoder, javaScriptStringEncoder)
{
if (htmlGenerator == null)
{
throw new ArgumentNullException(nameof(htmlGenerator));
}
if (viewEngine == null)
{
throw new ArgumentNullException(nameof(viewEngine));
}
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (htmlEncoder == null)
{
throw new ArgumentNullException(nameof(htmlEncoder));
}
if (urlEncoder == null)
{
throw new ArgumentNullException(nameof(urlEncoder));
}
if (javaScriptStringEncoder == null)
{
throw new ArgumentNullException(nameof(javaScriptStringEncoder));
}
}
/// <inheritdoc />
public new ViewDataDictionary<TModel> ViewData { get; private set; }
public override void Contextualize([NotNull] ViewContext viewContext)
public override void Contextualize(ViewContext viewContext)
{
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (viewContext.ViewData == null)
{
throw new ArgumentException(Resources.FormatPropertyOfTypeCannotBeNull(
@ -58,9 +86,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent CheckBoxFor(
[NotNull] Expression<Func<TModel, bool>> expression,
Expression<Func<TModel, bool>> expression,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateCheckBox(modelExplorer, GetExpressionName(expression), isChecked: null,
htmlAttributes: htmlAttributes);
@ -68,11 +101,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent DropDownListFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList,
string optionLabel,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = ExpressionMetadataProvider.FromLambdaExpression(expression, ViewData, MetadataProvider);
return GenerateDropDown(modelExplorer, ExpressionHelper.GetExpressionText(expression), selectList,
@ -81,11 +119,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent DisplayFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string templateName,
string htmlFieldName,
object additionalViewData)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = ExpressionMetadataProvider.FromLambdaExpression(expression,
ViewData,
MetadataProvider);
@ -97,16 +140,26 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public string DisplayNameFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression)
public string DisplayNameFor<TResult>(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateDisplayName(modelExplorer, ExpressionHelper.GetExpressionText(expression));
}
/// <inheritdoc />
public string DisplayNameForInnerType<TModelItem, TResult>(
[NotNull] Expression<Func<TModelItem, TResult>> expression)
Expression<Func<TModelItem, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = ExpressionMetadataProvider.FromLambdaExpression<TModelItem, TResult>(
expression,
new ViewDataDictionary<TModelItem>(ViewData, model: null),
@ -122,18 +175,28 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public string DisplayTextFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression)
public string DisplayTextFor<TResult>(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return GenerateDisplayText(GetModelExplorer(expression));
}
/// <inheritdoc />
public IHtmlContent EditorFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string templateName,
string htmlFieldName,
object additionalViewData)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = ExpressionMetadataProvider.FromLambdaExpression(expression, ViewData, MetadataProvider);
return GenerateEditor(
@ -145,9 +208,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent HiddenFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateHidden(
modelExplorer,
@ -158,17 +226,27 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public string IdFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression)
public string IdFor<TResult>(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return GenerateId(GetExpressionName(expression));
}
/// <inheritdoc />
public IHtmlContent LabelFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string labelText,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateLabel(
modelExplorer,
@ -179,10 +257,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent ListBoxFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
IEnumerable<SelectListItem> selectList,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
var name = ExpressionHelper.GetExpressionText(expression);
@ -190,17 +273,27 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public string NameFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression)
public string NameFor<TResult>(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var expressionName = GetExpressionName(expression);
return Name(expressionName);
}
/// <inheritdoc />
public IHtmlContent PasswordFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GeneratePassword(
modelExplorer,
@ -211,10 +304,20 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent RadioButtonFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
[NotNull] object value,
Expression<Func<TModel, TResult>> expression,
object value,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateRadioButton(
modelExplorer,
@ -226,21 +329,31 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent TextAreaFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
int rows,
int columns,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateTextArea(modelExplorer, GetExpressionName(expression), rows, columns, htmlAttributes);
}
/// <inheritdoc />
public IHtmlContent TextBoxFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string format,
object htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateTextBox(
modelExplorer,
@ -250,13 +363,23 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
htmlAttributes);
}
protected string GetExpressionName<TResult>([NotNull] Expression<Func<TModel, TResult>> expression)
protected string GetExpressionName<TResult>(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return ExpressionHelper.GetExpressionText(expression);
}
protected ModelExplorer GetModelExplorer<TResult>([NotNull] Expression<Func<TModel, TResult>> expression)
protected ModelExplorer GetModelExplorer<TResult>(Expression<Func<TModel, TResult>> expression)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = ExpressionMetadataProvider.FromLambdaExpression(expression, ViewData, MetadataProvider);
if (modelExplorer == null)
{
@ -269,11 +392,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
public IHtmlContent ValidationMessageFor<TResult>(
[NotNull] Expression<Func<TModel, TResult>> expression,
Expression<Func<TModel, TResult>> expression,
string message,
object htmlAttributes,
string tag)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
return GenerateValidationMessage(ExpressionHelper.GetExpressionText(expression),
message,
htmlAttributes,
@ -281,8 +409,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public string ValueFor<TResult>([NotNull] Expression<Func<TModel, TResult>> expression, string format)
public string ValueFor<TResult>(Expression<Func<TModel, TResult>> expression, string format)
{
if (expression == null)
{
throw new ArgumentNullException(nameof(expression));
}
var modelExplorer = GetModelExplorer(expression);
return GenerateValue(
ExpressionHelper.GetExpressionText(expression),

View File

@ -6,7 +6,6 @@ using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
string FormatValue(object value, string format);
TagBuilder GenerateActionLink(
[NotNull] string linkText,
string linkText,
string actionName,
string controllerName,
string protocol,
@ -38,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </summary>
/// <param name="viewContext">The <see cref="ViewContext"/> instance for the current scope.</param>
/// <returns>An <see cref="IHtmlContent"/> instance for the &lt;input type="hidden".../&gt; element.</returns>
IHtmlContent GenerateAntiforgery([NotNull] ViewContext viewContext);
IHtmlContent GenerateAntiforgery(ViewContext viewContext);
/// <summary>
/// Generate a &lt;input type="checkbox".../&gt; element.
@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// A <see cref="TagBuilder"/> instance for the &lt;input type="checkbox".../&gt; element.
/// </returns>
TagBuilder GenerateCheckBox(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
bool? isChecked,
@ -67,7 +66,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// checkbox was present on the page when the request was submitted.
/// </summary>
TagBuilder GenerateHiddenForCheckbox(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression);
@ -93,7 +92,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// A <see cref="TagBuilder"/> instance for the &lt;/form&gt; element.
/// </returns>
TagBuilder GenerateForm(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string actionName,
string controllerName,
object routeValues,
@ -121,14 +120,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// A <see cref="TagBuilder"/> instance for the &lt;/form&gt; element.
/// </returns>
TagBuilder GenerateRouteForm(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string routeName,
object routeValues,
string method,
object htmlAttributes);
TagBuilder GenerateHidden(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
@ -136,21 +135,21 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object htmlAttributes);
TagBuilder GenerateLabel(
[NotNull] ViewContext viewContext,
[NotNull] ModelExplorer modelExplorer,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
string labelText,
object htmlAttributes);
TagBuilder GeneratePassword(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
object htmlAttributes);
TagBuilder GenerateRadioButton(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
@ -158,7 +157,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object htmlAttributes);
TagBuilder GenerateRouteLink(
[NotNull] string linkText,
string linkText,
string routeName,
string protocol,
string hostName,
@ -201,7 +200,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </para>
/// </remarks>
TagBuilder GenerateSelect(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string optionLabel,
string expression,
@ -250,7 +249,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </para>
/// </remarks>
TagBuilder GenerateSelect(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string optionLabel,
string expression,
@ -260,7 +259,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object htmlAttributes);
TagBuilder GenerateTextArea(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
int rows,
@ -268,7 +267,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object htmlAttributes);
TagBuilder GenerateTextBox(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
object value,
@ -276,14 +275,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
object htmlAttributes);
TagBuilder GenerateValidationMessage(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
string expression,
string message,
string tag,
object htmlAttributes);
TagBuilder GenerateValidationSummary(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
bool excludePropertyErrors,
string message,
string headerTag,
@ -294,7 +293,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// implementations.
/// </remarks>
IEnumerable<ModelClientValidationRule> GetClientValidationRules(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression);
@ -333,7 +332,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// See <see cref="GenerateSelect"/> for information about how the return value may be used.
/// </remarks>
IReadOnlyCollection<string> GetCurrentValues(
[NotNull] ViewContext viewContext,
ViewContext viewContext,
ModelExplorer modelExplorer,
string expression,
bool allowMultiple);

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -17,13 +16,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </summary>
/// <param name="context">The <see cref="HttpContext"/>.</param>
/// <returns>The temporary data.</returns>
IDictionary<string, object> LoadTempData([NotNull] HttpContext context);
IDictionary<string, object> LoadTempData(HttpContext context);
/// <summary>
/// Saves the temporary data.
/// </summary>
/// <param name="context">The <see cref="HttpContext"/>.</param>
/// <param name="values">The values to save.</param>
void SaveTempData([NotNull] HttpContext context, IDictionary<string, object> values);
void SaveTempData(HttpContext context, IDictionary<string, object> values);
}
}

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
using System.IO;
using Newtonsoft.Json;
using Microsoft.Framework.Internal;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Rendering;
@ -21,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// Initializes a new instance of <see cref="JsonHelper"/> that is backed by <paramref name="jsonOutputFormatter"/>.
/// </summary>
/// <param name="jsonOutputFormatter">The <see cref="JsonOutputFormatter"/> used to serialize JSON.</param>
public JsonHelper([NotNull] JsonOutputFormatter jsonOutputFormatter)
public JsonHelper(JsonOutputFormatter jsonOutputFormatter)
{
if (jsonOutputFormatter == null)
{
throw new ArgumentNullException(nameof(jsonOutputFormatter));
}
_jsonOutputFormatter = jsonOutputFormatter;
}
@ -33,8 +38,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public HtmlString Serialize(object value, [NotNull] JsonSerializerSettings serializerSettings)
public HtmlString Serialize(object value, JsonSerializerSettings serializerSettings)
{
if (serializerSettings == null)
{
throw new ArgumentNullException(nameof(serializerSettings));
}
var jsonOutputFormatter = new JsonOutputFormatter(serializerSettings);
return SerializeInternal(jsonOutputFormatter, value);

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Rendering
{
@ -20,8 +20,18 @@ namespace Microsoft.AspNet.Mvc.Rendering
/// <param name="modelExplorer">
/// Includes the model and metadata about the <see cref="System.Linq.Expressions.Expression"/> of interest.
/// </param>
public ModelExpression([NotNull] string name, [NotNull] ModelExplorer modelExplorer)
public ModelExpression(string name, ModelExplorer modelExplorer)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (modelExplorer == null)
{
throw new ArgumentNullException(nameof(modelExplorer));
}
Name = name;
ModelExplorer = modelExplorer;
}

View File

@ -52,8 +52,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
};
/// <inheritdoc />
public virtual IDictionary<string, object> LoadTempData([NotNull] HttpContext context)
public virtual IDictionary<string, object> LoadTempData(HttpContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (!IsSessionEnabled(context))
{
// Session middleware is not enabled. No-op
@ -150,8 +155,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public virtual void SaveTempData([NotNull] HttpContext context, IDictionary<string, object> values)
public virtual void SaveTempData(HttpContext context, IDictionary<string, object> values)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var hasValues = (values != null && values.Count > 0);
if (hasValues)
{

View File

@ -8,7 +8,6 @@ using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.ViewFeatures
@ -61,8 +60,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public override void Write([NotNull] char[] buffer, int index, int count)
public override void Write(char[] buffer, int index, int count)
{
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index));
@ -112,8 +116,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public override Task WriteAsync([NotNull] char[] buffer, int index, int count)
public override Task WriteAsync(char[] buffer, int index, int count)
{
if (buffer == null)
{
throw new ArgumentNullException(nameof(buffer));
}
Write(buffer, index, count);
return _completedTask;
}

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.IO;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
namespace Microsoft.AspNet.Mvc.ViewFeatures
@ -27,8 +27,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
/// <inheritdoc />
public void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder)
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
{
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (encoder == null)
{
throw new ArgumentNullException(nameof(encoder));
}
encoder.HtmlEncode(_input, writer);
}

View File

@ -5,7 +5,6 @@ using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -24,8 +23,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </summary>
/// <param name="context">The <see cref="IHttpContextAccessor"/> that provides the HttpContext.</param>
/// <param name="provider">The <see cref="ITempDataProvider"/> used to Load and Save data.</param>
public TempDataDictionary([NotNull] IHttpContextAccessor context, [NotNull] ITempDataProvider provider)
public TempDataDictionary(IHttpContextAccessor context, ITempDataProvider provider)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
_provider = provider;
_loaded = false;
_contextAccessor = context;

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
{
@ -24,15 +24,35 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
private object _additionalViewData;
public TemplateBuilder(
[NotNull] IViewEngine viewEngine,
[NotNull] ViewContext viewContext,
[NotNull] ViewDataDictionary viewData,
[NotNull] ModelExplorer modelExplorer,
IViewEngine viewEngine,
ViewContext viewContext,
ViewDataDictionary viewData,
ModelExplorer modelExplorer,
string htmlFieldName,
string templateName,
bool readOnly,
object additionalViewData)
{
if (viewEngine == null)
{
throw new ArgumentNullException(nameof(viewEngine));
}
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
if (modelExplorer == null)
{
throw new ArgumentNullException(nameof(modelExplorer));
}
_viewEngine = viewEngine;
_viewContext = viewContext;
_viewData = viewData;

View File

@ -12,7 +12,6 @@ using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
{
@ -75,12 +74,27 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
private bool _readOnly;
public TemplateRenderer(
[NotNull] IViewEngine viewEngine,
[NotNull] ViewContext viewContext,
[NotNull] ViewDataDictionary viewData,
IViewEngine viewEngine,
ViewContext viewContext,
ViewDataDictionary viewData,
string templateName,
bool readOnly)
{
if (viewEngine == null)
{
throw new ArgumentNullException(nameof(viewEngine));
}
if (viewContext == null)
{
throw new ArgumentNullException(nameof(viewContext));
}
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
_viewEngine = viewEngine;
_viewContext = viewContext;
_viewData = viewData;

View File

@ -20,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
private static readonly MethodInfo _strongTryGetValueImplInfo =
typeof(TryGetValueProvider).GetTypeInfo().GetDeclaredMethod("StrongTryGetValueImpl");
public static TryGetValueDelegate CreateInstance([NotNull] Type targetType)
public static TryGetValueDelegate CreateInstance(Type targetType)
{
if (targetType == null)
{
throw new ArgumentNullException(nameof(targetType));
}
TryGetValueDelegate result;
// Cache delegates since properties of model types are re-evaluated numerous times.

View File

@ -5,16 +5,19 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
public static class UnobtrusiveValidationAttributesGenerator
{
public static IDictionary<string, object> GetValidationAttributes(
[NotNull] IEnumerable<ModelClientValidationRule> clientRules)
IEnumerable<ModelClientValidationRule> clientRules)
{
if (clientRules == null)
{
throw new ArgumentNullException(nameof(clientRules));
}
IDictionary<string, object> results = null;
foreach (var rule in clientRules)

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Antiforgery;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -12,13 +12,23 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
{
private readonly IAntiforgery _antiforgery;
public ValidateAntiforgeryTokenAuthorizationFilter([NotNull] IAntiforgery antiforgery)
public ValidateAntiforgeryTokenAuthorizationFilter(IAntiforgery antiforgery)
{
if (antiforgery == null)
{
throw new ArgumentNullException(nameof(antiforgery));
}
_antiforgery = antiforgery;
}
public Task OnAuthorizationAsync([NotNull] AuthorizationContext context)
public Task OnAuthorizationAsync(AuthorizationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return _antiforgery.ValidateRequestAsync(context.HttpContext);
}
}

View File

@ -29,10 +29,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <param name="modelState"><see cref="ModelStateDictionary"/> instance for this scope.</param>
/// <remarks>For use when creating a <see cref="ViewDataDictionary"/> for a new top-level scope.</remarks>
public ViewDataDictionary(
[NotNull] IModelMetadataProvider metadataProvider,
[NotNull] ModelStateDictionary modelState)
IModelMetadataProvider metadataProvider,
ModelStateDictionary modelState)
: this(metadataProvider, modelState, declaredModelType: typeof(object))
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
}
/// <summary>
@ -45,9 +53,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <see cref="Type"/> will not change e.g. when copying from a <see cref="ViewDataDictionary{TModel}"/>
/// instance to a base <see cref="ViewDataDictionary"/> instance.
/// </remarks>
public ViewDataDictionary([NotNull] ViewDataDictionary source)
public ViewDataDictionary(ViewDataDictionary source)
: this(source, source.Model, source._declaredModelType)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -62,9 +74,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <see cref="Model"/> is known. In this case, <see cref="object"/> is the best possible guess about the
/// declared type when <paramref name="model"/> is <c>null</c>.
/// </remarks>
public ViewDataDictionary([NotNull] ViewDataDictionary source, object model)
public ViewDataDictionary(ViewDataDictionary source, object model)
: this(source, model, declaredModelType: typeof(object))
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -75,9 +91,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <see cref="ViewDataDictionary.ModelMetadata"/> values.
/// </param>
/// <remarks>Internal for testing.</remarks>
internal ViewDataDictionary([NotNull] IModelMetadataProvider metadataProvider)
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
: this(metadataProvider, new ModelStateDictionary())
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
}
/// <summary>
@ -95,10 +115,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// For use when creating a derived <see cref="ViewDataDictionary"/> for a new top-level scope.
/// </remarks>
protected ViewDataDictionary(
[NotNull] IModelMetadataProvider metadataProvider,
[NotNull] Type declaredModelType)
IModelMetadataProvider metadataProvider,
Type declaredModelType)
: this(metadataProvider, new ModelStateDictionary(), declaredModelType)
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (declaredModelType == null)
{
throw new ArgumentNullException(nameof(declaredModelType));
}
}
/// <summary>
@ -117,15 +145,30 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// For use when creating a derived <see cref="ViewDataDictionary"/> for a new top-level scope.
/// </remarks>
protected ViewDataDictionary(
[NotNull] IModelMetadataProvider metadataProvider,
[NotNull] ModelStateDictionary modelState,
[NotNull] Type declaredModelType)
IModelMetadataProvider metadataProvider,
ModelStateDictionary modelState,
Type declaredModelType)
: this(metadataProvider,
modelState,
declaredModelType,
data: new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase),
templateInfo: new TemplateInfo())
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
if (declaredModelType == null)
{
throw new ArgumentNullException(nameof(declaredModelType));
}
// This is the core constructor called when Model is unknown. Base ModelMetadata on the declared type.
ModelExplorer = _metadataProvider.GetModelExplorerForType(declaredModelType, model: null);
}
@ -152,9 +195,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <see cref="ViewDataDictionary(ViewDataDictionary, object, Type)"/> to ignore <c>source.Model</c>.
/// </para>
/// </remarks>
protected ViewDataDictionary([NotNull] ViewDataDictionary source, Type declaredModelType)
protected ViewDataDictionary(ViewDataDictionary source, Type declaredModelType)
: this(source, model: source.Model, declaredModelType: declaredModelType)
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -178,13 +225,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <paramref name="declaredModelType"/>.
/// </para>
/// </remarks>
protected ViewDataDictionary([NotNull] ViewDataDictionary source, object model, Type declaredModelType)
protected ViewDataDictionary(ViewDataDictionary source, object model, Type declaredModelType)
: this(source._metadataProvider,
new ModelStateDictionary(source.ModelState),
declaredModelType,
data: new CopyOnWriteDictionary<string, object>(source, StringComparer.OrdinalIgnoreCase),
templateInfo: new TemplateInfo(source.TemplateInfo))
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
// This is the core constructor called when Model is known.
var modelType = GetModelType(model);
var metadataModelType = source.ModelMetadata.UnderlyingOrModelType;
@ -260,7 +312,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
public TemplateInfo TemplateInfo { get; }
#region IDictionary properties
#region IDictionary properties
// Do not just pass through to _data: Indexer should not throw a KeyNotFoundException.
public object this[string index]
{
@ -295,7 +347,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
{
get { return _data.Values; }
}
#endregion
#endregion
// for unit testing
internal IDictionary<string, object> Data
@ -448,28 +500,48 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
}
}
#region IDictionary methods
public void Add([NotNull] string key, object value)
#region IDictionary methods
public void Add(string key, object value)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
_data.Add(key, value);
}
public bool ContainsKey([NotNull] string key)
public bool ContainsKey(string key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _data.ContainsKey(key);
}
public bool Remove([NotNull] string key)
public bool Remove(string key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _data.Remove(key);
}
public bool TryGetValue([NotNull] string key, out object value)
public bool TryGetValue(string key, out object value)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
return _data.TryGetValue(key, out value);
}
public void Add([NotNull] KeyValuePair<string, object> item)
public void Add(KeyValuePair<string, object> item)
{
_data.Add(item);
}
@ -479,17 +551,22 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
_data.Clear();
}
public bool Contains([NotNull] KeyValuePair<string, object> item)
public bool Contains(KeyValuePair<string, object> item)
{
return _data.Contains(item);
}
public void CopyTo([NotNull] KeyValuePair<string, object>[] array, int arrayIndex)
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
{
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}
_data.CopyTo(array, arrayIndex);
}
public bool Remove([NotNull] KeyValuePair<string, object> item)
public bool Remove(KeyValuePair<string, object> item)
{
return _data.Remove(item);
}
@ -503,6 +580,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
{
return _data.GetEnumerator();
}
#endregion
#endregion
}
}

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -17,10 +17,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <inheritdoc />
// References may not show up due to ActivatorUtilities use in RazorPageActivator.
public ViewDataDictionary(
[NotNull] IModelMetadataProvider metadataProvider,
[NotNull] ModelStateDictionary modelState)
IModelMetadataProvider metadataProvider,
ModelStateDictionary modelState)
: base(metadataProvider, modelState, declaredModelType: typeof(TModel))
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
}
/// <summary>
@ -41,9 +49,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </remarks>
/// <inheritdoc />
// References may not show up due to ActivatorUtilities use in RazorPageActivator.
public ViewDataDictionary([NotNull] ViewDataDictionary source)
public ViewDataDictionary(ViewDataDictionary source)
: base(source, declaredModelType: typeof(TModel))
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -65,9 +77,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
// Model parameter type is object to allow "model: null" calls even when TModel is a value type. A TModel
// parameter would likely require IEquatable<TModel> type restrictions to pass expected null value to the base
// constructor.
public ViewDataDictionary([NotNull] ViewDataDictionary source, object model)
public ViewDataDictionary(ViewDataDictionary source, object model)
: base(source, model, declaredModelType: typeof(TModel))
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
}
/// <summary>
@ -75,9 +91,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// </summary>
/// <remarks>Internal for testing.</remarks>
/// <inheritdoc />
internal ViewDataDictionary([NotNull] IModelMetadataProvider metadataProvider)
internal ViewDataDictionary(IModelMetadataProvider metadataProvider)
: base(metadataProvider, declaredModelType: typeof(TModel))
{
if (metadataProvider == null)
{
throw new ArgumentNullException(nameof(metadataProvider));
}
}
public new TModel Model

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewFeatures
{
@ -20,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <returns>
/// <see cref="ViewDataInfo"/> for named <paramref name="expression"/> in given <paramref name="viewData"/>.
/// </returns>
public static ViewDataInfo Eval([NotNull] ViewDataDictionary viewData, string expression)
public static ViewDataInfo Eval(ViewDataDictionary viewData, string expression)
{
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
// While it is not valid to generate a field for the top-level model itself because the result is an
// unnamed input element, do not throw here if full name is null or empty. Support is needed for cases
// such as Html.Label() and Html.Value(), where the user's code is not creating a name attribute. Checks

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.ViewFeatures
@ -29,13 +29,38 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
/// <param name="tempData">The <see cref="ITempDataDictionary"/> for the view being rendered.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous rendering.</returns>
public static async Task ExecuteAsync(
[NotNull] IView view,
[NotNull] ActionContext actionContext,
[NotNull] ViewDataDictionary viewData,
[NotNull] ITempDataDictionary tempData,
[NotNull] HtmlHelperOptions htmlHelperOptions,
IView view,
ActionContext actionContext,
ViewDataDictionary viewData,
ITempDataDictionary tempData,
HtmlHelperOptions htmlHelperOptions,
MediaTypeHeaderValue contentType)
{
if (view == null)
{
throw new ArgumentNullException(nameof(view));
}
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (viewData == null)
{
throw new ArgumentNullException(nameof(viewData));
}
if (tempData == null)
{
throw new ArgumentNullException(nameof(tempData));
}
if (htmlHelperOptions == null)
{
throw new ArgumentNullException(nameof(htmlHelperOptions));
}
var response = actionContext.HttpContext.Response;
if (contentType != null && contentType.Encoding == null)

View File

@ -4,11 +4,9 @@
using System;
using System.Diagnostics.Tracing;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers;
@ -56,8 +54,13 @@ namespace Microsoft.AspNet.Mvc
public MediaTypeHeaderValue ContentType { get; set; }
/// <inheritdoc />
public override async Task ExecuteResultAsync([NotNull] ActionContext context)
public override async Task ExecuteResultAsync(ActionContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var services = context.HttpContext.RequestServices;
var viewEngine = ViewEngine ?? services.GetRequiredService<ICompositeViewEngine>();
@ -68,7 +71,7 @@ namespace Microsoft.AspNet.Mvc
var viewName = ViewName ?? context.ActionDescriptor.Name;
var viewEngineResult = viewEngine.FindView(context, viewName);
if(!viewEngineResult.Success)
if (!viewEngineResult.Success)
{
if (telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewResultViewNotFound"))
{
@ -84,7 +87,7 @@ namespace Microsoft.AspNet.Mvc
}
logger.LogError(
"The view '{ViewName}' was not found. Searched locations: {SearchedViewLocations}",
"The view '{ViewName}' was not found. Searched locations: {SearchedViewLocations}",
viewName,
viewEngineResult.SearchedLocations);
}

View File

@ -18,21 +18,12 @@
"Microsoft.Framework.BufferedHtmlContent.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.CopyOnWriteDictionary.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.PropertyActivator.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": ""
}
},
"dnxcore50": {
"dependencies": {
"System.ComponentModel.Annotations": "4.0.11-beta-*"
}
}
"dnx451": { },
"dnxcore50": { }
}
}

View File

@ -8,12 +8,15 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Html.Abstractions;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.PageExecutionInstrumentation;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.WebEncoders.Testing;
using Moq;
@ -1827,11 +1830,14 @@ namespace Microsoft.AspNet.Mvc.Razor
private static ViewContext CreateViewContext(TextWriter writer = null)
{
writer = writer ?? new StringWriter();
var actionContext = new ActionContext(new DefaultHttpContext(), routeData: null, actionDescriptor: null);
var actionContext = new ActionContext(
new DefaultHttpContext(),
new RouteData(),
new ActionDescriptor());
return new ViewContext(
actionContext,
Mock.Of<IView>(),
null,
new ViewDataDictionary(new EmptyModelMetadataProvider()),
Mock.Of<ITempDataDictionary>(),
writer,
new HtmlHelperOptions());

View File

@ -297,14 +297,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
var pageFactory = new Mock<IRazorPageFactory>();
var viewFactory = new Mock<IRazorViewFactory>();
var page = Mock.Of<IRazorPage>();
pageFactory.Setup(p => p.CreateInstance("fake-path1/bar/test-view.rzr"))
.Returns(Mock.Of<IRazorPage>())
.Verifiable();
var viewEngine = new OverloadedLocationViewEngine(pageFactory.Object,
viewFactory.Object,
GetOptionsAccessor(),
GetViewLocationCache());
pageFactory
.Setup(p => p.CreateInstance("fake-path1/bar/test-view.rzr"))
.Returns(page)
.Verifiable();
var viewEngine = new OverloadedLocationViewEngine(
pageFactory.Object,
viewFactory.Object,
GetOptionsAccessor(),
GetViewLocationCache());
var context = GetActionContext(_controllerTestContext);
viewFactory.Setup(v => v.GetView(viewEngine, page, false))
.Returns(Mock.Of<IView>());
// Act
var result = viewEngine.FindView(context, "test-view");
@ -320,14 +324,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
var pageFactory = new Mock<IRazorPageFactory>();
var viewFactory = new Mock<IRazorViewFactory>();
var page = Mock.Of<IRazorPage>();
pageFactory.Setup(p => p.CreateInstance("fake-area-path/foo/bar/test-view2.rzr"))
.Returns(Mock.Of<IRazorPage>())
.Verifiable();
var viewEngine = new OverloadedLocationViewEngine(pageFactory.Object,
viewFactory.Object,
GetOptionsAccessor(),
GetViewLocationCache());
pageFactory
.Setup(p => p.CreateInstance("fake-area-path/foo/bar/test-view2.rzr"))
.Returns(page)
.Verifiable();
var viewEngine = new OverloadedLocationViewEngine(
pageFactory.Object,
viewFactory.Object,
GetOptionsAccessor(),
GetViewLocationCache());
var context = GetActionContext(_areaTestContext);
viewFactory.Setup(v => v.GetView(viewEngine, page, false))
.Returns(Mock.Of<IView>());
// Act
var result = viewEngine.FindView(context, "test-view2");

View File

@ -8,10 +8,12 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.PageExecutionInstrumentation;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.WebEncoders.Testing;
using Moq;
using Xunit;
@ -1404,12 +1406,13 @@ namespace Microsoft.AspNet.Mvc.Razor
viewEngine.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "/Layout.cshtml"))
.Returns(new RazorPageResult("Layout", layout));
var view = new RazorView(viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(viewStart),
page,
new CommonTestEncoder(),
isPartial: false);
var view = new RazorView(
viewEngine.Object,
Mock.Of<IRazorPageActivator>(),
CreateViewStartProvider(viewStart),
page,
new CommonTestEncoder(),
isPartial: false);
var viewContext = CreateViewContext(view);
// Act
@ -1457,7 +1460,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private static ViewContext CreateViewContext(RazorView view)
{
var httpContext = new DefaultHttpContext();
var actionContext = new ActionContext(httpContext, routeData: null, actionDescriptor: null);
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
return new ViewContext(
actionContext,
view,
@ -1471,8 +1474,9 @@ namespace Microsoft.AspNet.Mvc.Razor
{
viewStartPages = viewStartPages ?? new IRazorPage[0];
var viewStartProvider = new Mock<IViewStartProvider>();
viewStartProvider.Setup(v => v.GetViewStartPages(It.IsAny<string>()))
.Returns(viewStartPages);
viewStartProvider
.Setup(v => v.GetViewStartPages(It.IsAny<string>()))
.Returns(viewStartPages);
return viewStartProvider.Object;
}

View File

@ -13,6 +13,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.ViewFeatures;
@ -1753,6 +1754,7 @@ namespace Microsoft.AspNet.Mvc.Test
{
ModelBinder = binder,
ValueProvider = provider,
InputFormatters = new List<IInputFormatter>(),
ValidatorProvider = new DataAnnotationsModelValidatorProvider(
options: null,
stringLocalizerFactory: null)

View File

@ -7,7 +7,9 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel;
@ -23,27 +25,32 @@ namespace Microsoft.AspNet.Mvc
public async Task ExecuteResultAsync_ReturnsError_IfViewCouldNotBeFound()
{
// Arrange
var expected = string.Join(Environment.NewLine,
"The view 'MyView' was not found. The following locations were searched:",
"Location1",
"Location2.");
var actionContext = new ActionContext(GetHttpContext(),
new RouteData(),
new ActionDescriptor());
var expected = string.Join(
Environment.NewLine,
"The view 'MyView' was not found. The following locations were searched:",
"Location1",
"Location2.");
var actionContext = new ActionContext(
GetHttpContext(),
new RouteData(),
new ActionDescriptor());
var viewEngine = new Mock<IViewEngine>();
viewEngine.Setup(v => v.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
.Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" }))
.Verifiable();
viewEngine
.Setup(v => v.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
.Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" }))
.Verifiable();
var viewResult = new PartialViewResult
{
ViewEngine = viewEngine.Object,
ViewName = "MyView"
ViewName = "MyView",
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
TempData = Mock.Of<ITempDataDictionary>(),
};
// Act and Assert
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
() => viewResult.ExecuteResultAsync(actionContext));
() => viewResult.ExecuteResultAsync(actionContext));
Assert.Equal(expected, ex.Message);
viewEngine.Verify();
}
@ -57,14 +64,17 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>();
var view = Mock.Of<IView>();
viewEngine.Setup(e => e.FindPartialView(context, "myview"))
.Returns(ViewEngineResult.Found("myview", view))
.Verifiable();
viewEngine
.Setup(e => e.FindPartialView(context, "myview"))
.Returns(ViewEngineResult.Found("myview", view))
.Verifiable();
var viewResult = new PartialViewResult
{
ViewName = viewName,
ViewEngine = viewEngine.Object
ViewEngine = viewEngine.Object,
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
TempData = Mock.Of<ITempDataDictionary>(),
};
// Act
@ -109,14 +119,17 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>();
var view = Mock.Of<IView>();
viewEngine.Setup(e => e.FindPartialView(context, "myview"))
.Returns(ViewEngineResult.Found("myview", view));
viewEngine
.Setup(e => e.FindPartialView(context, "myview"))
.Returns(ViewEngineResult.Found("myview", view));
var viewResult = new PartialViewResult
{
ViewName = viewName,
ViewEngine = viewEngine.Object,
ContentType = contentType
ContentType = contentType,
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
TempData = Mock.Of<ITempDataDictionary>(),
};
// Act
@ -136,14 +149,17 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>();
var view = Mock.Of<IView>();
viewEngine.Setup(e => e.FindPartialView(context, "myview"))
.Returns(ViewEngineResult.Found("myview", view));
viewEngine
.Setup(e => e.FindPartialView(context, "myview"))
.Returns(ViewEngineResult.Found("myview", view));
var viewResult = new PartialViewResult
{
ViewName = viewName,
ViewEngine = viewEngine.Object,
StatusCode = 404,
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
TempData = Mock.Of<ITempDataDictionary>(),
};
// Act
@ -158,17 +174,21 @@ namespace Microsoft.AspNet.Mvc
{
// Arrange
var viewName = "some-view-name";
var context = new ActionContext(GetHttpContext(),
new RouteData(),
new ActionDescriptor { Name = viewName });
var context = new ActionContext(
GetHttpContext(),
new RouteData(),
new ActionDescriptor { Name = viewName });
var viewEngine = new Mock<ICompositeViewEngine>();
viewEngine.Setup(e => e.FindPartialView(context, viewName))
.Returns(ViewEngineResult.Found(viewName, Mock.Of<IView>()))
.Verifiable();
viewEngine
.Setup(e => e.FindPartialView(context, viewName))
.Returns(ViewEngineResult.Found(viewName, Mock.Of<IView>()))
.Verifiable();
var viewResult = new PartialViewResult
{
ViewEngine = viewEngine.Object
ViewEngine = viewEngine.Object,
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
TempData = Mock.Of<ITempDataDictionary>(),
};
// Act
@ -183,19 +203,23 @@ namespace Microsoft.AspNet.Mvc
{
// Arrange
var viewName = "partial-view-name";
var context = new ActionContext(new DefaultHttpContext(),
new RouteData(),
new ActionDescriptor { Name = viewName });
var context = new ActionContext(
new DefaultHttpContext(),
new RouteData(),
new ActionDescriptor { Name = viewName });
var viewEngine = new Mock<ICompositeViewEngine>();
viewEngine.Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), viewName))
.Returns(ViewEngineResult.Found(viewName, Mock.Of<IView>()))
.Verifiable();
viewEngine
.Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), viewName))
.Returns(ViewEngineResult.Found(viewName, Mock.Of<IView>()))
.Verifiable();
var serviceProvider = new Mock<IServiceProvider>();
serviceProvider.Setup(p => p.GetService(typeof(ICompositeViewEngine)))
.Returns(viewEngine.Object);
serviceProvider.Setup(p => p.GetService(typeof(ILogger<PartialViewResult>)))
.Returns(new Mock<ILogger<PartialViewResult>>().Object);
serviceProvider
.Setup(p => p.GetService(typeof(ICompositeViewEngine)))
.Returns(viewEngine.Object);
serviceProvider
.Setup(p => p.GetService(typeof(ILogger<PartialViewResult>)))
.Returns(new Mock<ILogger<PartialViewResult>>().Object);
serviceProvider.Setup(s => s.GetService(typeof(IOptions<MvcViewOptions>)))
.Returns(() => {
var optionsAccessor = new Mock<IOptions<MvcViewOptions>>();
@ -207,7 +231,9 @@ namespace Microsoft.AspNet.Mvc
var viewResult = new PartialViewResult
{
ViewName = viewName
ViewName = viewName,
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()),
TempData = Mock.Of<ITempDataDictionary>(),
};
// Act

View File

@ -285,7 +285,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
actionContext,
Mock.Of<IView>(),
viewData,
null,
new TempDataDictionary(
new HttpContextAccessor(),
Mock.Of<ITempDataProvider>()),
new StringWriter(),
options.HtmlHelperOptions);

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
using Moq;
using Xunit;
@ -1563,7 +1562,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
private class TestHtmlHelper : HtmlHelper
{
public TestHtmlHelper([NotNull] IModelMetadataProvider metadataProvider)
public TestHtmlHelper(IModelMetadataProvider metadataProvider)
: base(
new Mock<IHtmlGenerator>(MockBehavior.Strict).Object,
new Mock<ICompositeViewEngine>(MockBehavior.Strict).Object,
@ -1580,7 +1579,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public IEnumerable<SelectListItem> CopiedSelectListItems { get; private set; }
protected override IEnumerable<SelectListItem> GetEnumSelectList([NotNull] ModelMetadata metadata)
protected override IEnumerable<SelectListItem> GetEnumSelectList(ModelMetadata metadata)
{
Metadata = metadata;
SelectListItems = base.GetEnumSelectList(metadata);

View File

@ -1,8 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Routing;
using Moq;
using Xunit;
namespace Microsoft.AspNet.Mvc.Rendering
@ -12,15 +18,15 @@ namespace Microsoft.AspNet.Mvc.Rendering
[Fact]
public void SettingViewData_AlsoUpdatesViewBag()
{
// Arrange (eventually passing null to these consturctors will throw)
// Arrange
var originalViewData = new ViewDataDictionary(metadataProvider: new EmptyModelMetadataProvider());
var context = new ViewContext(
new ActionContext(null, null, null),
view: null,
viewData: null,
tempData: null,
writer: null,
new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()),
view: Mock.Of<IView>(),
viewData: originalViewData,
tempData: new TempDataDictionary(new HttpContextAccessor(), Mock.Of<ITempDataProvider>()),
writer: TextWriter.Null,
htmlHelperOptions: new HtmlHelperOptions());
var originalViewData = context.ViewData = new ViewDataDictionary(metadataProvider: new EmptyModelMetadataProvider());
var replacementViewData = new ViewDataDictionary(metadataProvider: new EmptyModelMetadataProvider());
// Act

View File

@ -13,28 +13,34 @@ using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewComponents;
using Microsoft.AspNet.Mvc.ViewFeatures;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers;
using Moq;
using Xunit;
namespace Microsoft.AspNet.Mvc
{
public class ViewComponentResultTest
{
private readonly ITempDataDictionary _tempDataDictionary =
new TempDataDictionary(new HttpContextAccessor(), new SessionStateTempDataProvider());
[Fact]
public async Task ExecuteResultAsync_Throws_IfNameOrTypeIsNotSet()
{
// Arrange
var expected =
var expected =
"Either the 'ViewComponentName' or 'ViewComponentType' " +
"property must be set in order to invoke a view component.";
var actionContext = CreateActionContext();
var viewComponentResult = new ViewComponentResult();
var viewComponentResult = new ViewComponentResult
{
TempData = _tempDataDictionary,
};
// Act and Assert
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
@ -53,6 +59,7 @@ namespace Microsoft.AspNet.Mvc
var viewComponentResult = new ViewComponentResult
{
ViewComponentName = "Text",
TempData = _tempDataDictionary,
};
// Act and Assert
@ -75,6 +82,7 @@ namespace Microsoft.AspNet.Mvc
var viewComponentResult = new ViewComponentResult
{
ViewComponentType = typeof(TextViewComponent),
TempData = _tempDataDictionary,
};
// Act and Assert
@ -100,6 +108,7 @@ namespace Microsoft.AspNet.Mvc
{
Arguments = new object[] { "World!" },
ViewComponentName = "Text",
TempData = _tempDataDictionary,
};
// Act
@ -127,6 +136,7 @@ namespace Microsoft.AspNet.Mvc
{
Arguments = new object[] { "World!" },
ViewComponentName = "AsyncText",
TempData = _tempDataDictionary,
};
// Act
@ -154,6 +164,7 @@ namespace Microsoft.AspNet.Mvc
{
Arguments = new object[] { "World!" },
ViewComponentName = "Text",
TempData = _tempDataDictionary,
};
// Act
@ -181,6 +192,7 @@ namespace Microsoft.AspNet.Mvc
{
Arguments = new object[] { "World!" },
ViewComponentName = "Full.Name.Text",
TempData = _tempDataDictionary,
};
// Act
@ -208,6 +220,7 @@ namespace Microsoft.AspNet.Mvc
{
Arguments = new object[] { "World!" },
ViewComponentType = typeof(TextViewComponent),
TempData = _tempDataDictionary,
};
// Act
@ -236,6 +249,7 @@ namespace Microsoft.AspNet.Mvc
Arguments = new object[] { "World!" },
ViewComponentType = typeof(TextViewComponent),
StatusCode = 404,
TempData = _tempDataDictionary,
};
// Act
@ -293,7 +307,8 @@ namespace Microsoft.AspNet.Mvc
{
Arguments = new object[] { "World!" },
ViewComponentName = "Text",
ContentType = contentType
ContentType = contentType,
TempData = _tempDataDictionary,
};
// Act
@ -330,6 +345,7 @@ namespace Microsoft.AspNet.Mvc
Arguments = new object[] { "World!" },
ViewComponentName = "Text",
ContentType = new MediaTypeHeaderValue("text/html") { Encoding = Encoding.UTF8 },
TempData = _tempDataDictionary,
};
// Act
@ -359,6 +375,7 @@ namespace Microsoft.AspNet.Mvc
{
Arguments = new object[] { "World!" },
ViewComponentName = "Text",
TempData = _tempDataDictionary,
};
// Act

View File

@ -60,7 +60,8 @@ namespace Microsoft.AspNet.Mvc
var viewContext = new ViewContext(
actionContext,
view,
viewData, null,
viewData,
new TempDataDictionary(new HttpContextAccessor(), new SessionStateTempDataProvider()),
TextWriter.Null,
new HtmlHelperOptions());

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
using Xunit;
namespace Microsoft.AspNet.Mvc.ViewComponents
@ -187,7 +186,7 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
public Type[] AllowedTypes { get; private set; }
protected override bool IsViewComponentType([NotNull] TypeInfo typeInfo)
protected override bool IsViewComponentType(TypeInfo typeInfo)
{
return AllowedTypes.Contains(typeInfo.AsType());
}

View File

@ -71,7 +71,7 @@ namespace Microsoft.AspNet.Mvc
actionContext,
view,
viewData,
null,
Mock.Of<ITempDataDictionary>(),
TextWriter.Null,
new HtmlHelperOptions());

View File

@ -20,6 +20,9 @@ namespace Microsoft.AspNet.Mvc
{
public class ViewViewComponentResultTest
{
private readonly ITempDataDictionary _tempDataDictionary =
new TempDataDictionary(new HttpContextAccessor(), new SessionStateTempDataProvider());
[Fact]
public void Execute_RendersPartialViews()
{
@ -40,7 +43,8 @@ namespace Microsoft.AspNet.Mvc
{
ViewEngine = viewEngine.Object,
ViewName = "some-view",
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view.Object, viewData);
@ -72,7 +76,8 @@ namespace Microsoft.AspNet.Mvc
var result = new ViewViewComponentResult
{
ViewEngine = viewEngine.Object,
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view.Object, viewData);
@ -107,7 +112,8 @@ namespace Microsoft.AspNet.Mvc
{
ViewEngine = viewEngine.Object,
ViewName = "some-view",
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view, viewData);
@ -139,7 +145,8 @@ namespace Microsoft.AspNet.Mvc
{
ViewEngine = viewEngine.Object,
ViewName = "some-view",
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view.Object, viewData);
@ -169,7 +176,8 @@ namespace Microsoft.AspNet.Mvc
{
ViewEngine = viewEngine.Object,
ViewName = "some-view",
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view, viewData);
@ -201,7 +209,8 @@ namespace Microsoft.AspNet.Mvc
var result = new ViewViewComponentResult
{
ViewName = "some-view",
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view, viewData);
@ -239,7 +248,8 @@ namespace Microsoft.AspNet.Mvc
{
ViewEngine = viewEngine.Object,
ViewName = "some-view",
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view, viewData);
@ -266,7 +276,8 @@ namespace Microsoft.AspNet.Mvc
var result = new ViewViewComponentResult
{
ViewName = "some-view",
ViewData = viewData
ViewData = viewData,
TempData = _tempDataDictionary,
};
var viewComponentContext = GetViewComponentContext(view, viewData);
@ -299,6 +310,7 @@ namespace Microsoft.AspNet.Mvc
componentResult.ViewEngine = viewEngine.Object;
componentResult.ViewData = viewData;
componentResult.ViewName = viewName;
componentResult.TempData = _tempDataDictionary;
// Act & Assert
componentResult.Execute(componentContext);
@ -323,7 +335,8 @@ namespace Microsoft.AspNet.Mvc
{
ViewEngine = viewEngine.Object,
ViewData = viewData,
ViewName = viewName
ViewName = viewName,
TempData = _tempDataDictionary,
};
// Act & Assert
@ -338,7 +351,7 @@ namespace Microsoft.AspNet.Mvc
actionContext,
view,
viewData,
null,
new TempDataDictionary(new HttpContextAccessor(), new SessionStateTempDataProvider()),
TextWriter.Null,
new HtmlHelperOptions());

View File

@ -17,7 +17,6 @@ using Microsoft.AspNet.Mvc.TestCommon;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Mvc.ViewFeatures.Internal;
using Microsoft.AspNet.Testing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.WebEncoders;
using Moq;
using Xunit;
@ -426,7 +425,7 @@ Environment.NewLine;
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
null,
Mock.Of<IUrlHelper>(),
viewEngine.Object,
provider,
innerHelper => new StubbyHtmlHelper(innerHelper));
@ -465,7 +464,7 @@ Environment.NewLine;
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
null,
Mock.Of<IUrlHelper>(),
viewEngine.Object,
provider,
innerHelper => new StubbyHtmlHelper(innerHelper));
@ -503,7 +502,7 @@ Environment.NewLine;
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
null,
Mock.Of<IUrlHelper>(),
viewEngine.Object,
provider,
innerHelper => new StubbyHtmlHelper(innerHelper));
@ -542,7 +541,7 @@ Environment.NewLine;
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
null,
Mock.Of<IUrlHelper>(),
viewEngine.Object,
provider,
innerHelper => new StubbyHtmlHelper(innerHelper));
@ -624,7 +623,7 @@ Environment.NewLine;
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
null,
Mock.Of<IUrlHelper>(),
viewEngine.Object,
provider);
helper.ViewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix";
@ -678,7 +677,7 @@ Environment.NewLine;
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
null,
Mock.Of<IUrlHelper>(),
viewEngine.Object,
provider);
helper.Html5DateRenderingMode = Html5DateRenderingMode.Rfc3339;
@ -737,7 +736,7 @@ Environment.NewLine;
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
null,
Mock.Of<IUrlHelper>(),
viewEngine.Object,
provider);
@ -929,13 +928,13 @@ Environment.NewLine;
get { return _innerHelper.JavaScriptStringEncoder; }
}
public void Contextualize([NotNull] ViewContext viewContext)
public void Contextualize(ViewContext viewContext)
{
(_innerHelper as ICanHasViewContext)?.Contextualize(viewContext);
}
public IHtmlContent ActionLink(
[NotNull] string linkText,
string linkText,
string actionName,
string controllerName,
string protocol,
@ -1033,7 +1032,7 @@ Environment.NewLine;
throw new NotImplementedException();
}
public string GenerateIdFromName([NotNull] string name)
public string GenerateIdFromName(string name)
{
throw new NotImplementedException();
}
@ -1050,7 +1049,7 @@ Environment.NewLine;
throw new NotImplementedException();
}
public IEnumerable<SelectListItem> GetEnumSelectList([NotNull] Type enumType)
public IEnumerable<SelectListItem> GetEnumSelectList(Type enumType)
{
throw new NotImplementedException();
}
@ -1081,7 +1080,7 @@ Environment.NewLine;
}
public Task<IHtmlContent> PartialAsync(
[NotNull] string partialViewName,
string partialViewName,
object model,
ViewDataDictionary viewData)
{
@ -1108,13 +1107,13 @@ Environment.NewLine;
throw new NotImplementedException();
}
public Task RenderPartialAsync([NotNull] string partialViewName, object model, ViewDataDictionary viewData)
public Task RenderPartialAsync(string partialViewName, object model, ViewDataDictionary viewData)
{
throw new NotImplementedException();
}
public IHtmlContent RouteLink(
[NotNull] string linkText,
string linkText,
string routeName,
string protocol,
string hostName,

View File

@ -6,10 +6,13 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.AspNet.Antiforgery;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Mvc.ViewEngines;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.OptionsModel;
using Microsoft.Framework.WebEncoders;
using Moq;
@ -661,7 +664,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
// GetCurrentValues uses only the ModelStateDictionary and ViewDataDictionary from the passed ViewContext.
private static ViewContext GetViewContext<TModel>(TModel model, IModelMetadataProvider metadataProvider)
{
var actionContext = new ActionContext();
var actionContext = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
var viewData = new ViewDataDictionary<TModel>(metadataProvider, actionContext.ModelState)
{
Model = model,

Some files were not shown because too many files have changed in this diff Show More