Show / Hide Table of Contents

    Class ChameleonFormExtensions

    Default extension methods for Form<TModel>.

    Inheritance
    System.Object
    ChameleonFormExtensions
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: ChameleonForms
    Assembly: ChameleonForms.dll
    Syntax
    public static class ChameleonFormExtensions

    Methods

    | Improve this Doc View Source

    BeginChameleonForm<TModel>(IHtmlHelper<TModel>, String, FormMethod, HtmlAttributes, Nullable<EncType>, Nullable<Boolean>)

    Constructs a Form<TModel> object with the default ChameleonForms template renderer.

    Declaration
    public static IForm<TModel> BeginChameleonForm<TModel>(this IHtmlHelper<TModel> helper, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType? enctype = default(EncType? ), bool? outputAntiforgeryToken = default(bool? ))
    Parameters
    Type Name Description
    Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> helper

    The HTML Helper for the current view

    System.String action

    The action the form should submit to

    Microsoft.AspNetCore.Mvc.Rendering.FormMethod method

    The HTTP method the form submission should use

    HtmlAttributes htmlAttributes

    Any HTML attributes the form should use

    System.Nullable<EncType> enctype

    The encoding type the form submission should use

    System.Nullable<System.Boolean> outputAntiforgeryToken

    Whether or not to output an antiforgery token in the form; defaults to null which will output a token if the method isn't GET

    Returns
    Type Description
    IForm<TModel>

    A Form<TModel> object with an instance of the default form template renderer.

    Type Parameters
    Name Description
    TModel

    The view model type for the current view

    Examples

    @using (var f = Html.BeginChameleonForm(...)) { ... }

    | Improve this Doc View Source

    BeginChameleonFormFor<TOriginalModel, TNewModel>(IHtmlHelper<TOriginalModel>, TNewModel, String, FormMethod, HtmlAttributes, Nullable<EncType>, Nullable<Boolean>)

    Constructs a Form<TModel> object with the default ChameleonForms template renderer using the given model type and instance. Values will bind back to the model type specified as if that was the model all along.

    Declaration
    public static IForm<TNewModel> BeginChameleonFormFor<TOriginalModel, TNewModel>(this IHtmlHelper<TOriginalModel> helper, TNewModel model, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType? enctype = default(EncType? ), bool? outputAntiforgeryToken = default(bool? ))
    Parameters
    Type Name Description
    Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TOriginalModel> helper

    The HTML Helper for the current view

    TNewModel model

    The model to use for the form

    System.String action

    The action the form should submit to

    Microsoft.AspNetCore.Mvc.Rendering.FormMethod method

    The HTTP method the form submission should use

    HtmlAttributes htmlAttributes

    Any HTML attributes the form should use

    System.Nullable<EncType> enctype

    The encoding type the form submission should use

    System.Nullable<System.Boolean> outputAntiforgeryToken

    Whether or not to output an antiforgery token in the form; defaults to null which will output a token if the method isn't GET

    Returns
    Type Description
    IForm<TNewModel>

    A Form<TModel> object with an instance of the default form template renderer.

    Type Parameters
    Name Description
    TOriginalModel

    The model type of the view

    TNewModel

    The model type of the sub-property to construct the form for

    Remarks

    This can also be done using the For() HTML helper extension method and just a type: @using (var f = Html.For<AnotherModelType>().BeginChameleonForm(...)) { ... }

    Examples

    @using (var f = Html.BeginChameleonFormFor(new AnotherModelType(), ...)) { ... } @using (var f = Html.BeginChameleonFormFor(default(AnotherModelType), ...)) { ... }

    | Improve this Doc View Source

    BeginChameleonFormFor<TParentModel, TChildModel>(IHtmlHelper<TParentModel>, Expression<Func<TParentModel, TChildModel>>, String, FormMethod, HtmlAttributes, Nullable<EncType>, Nullable<Boolean>)

    Constructs a Form<TModel> object with the default ChameleonForms template renderer using a sub-property of the current model as the model. Values will bind back to the model type of the sub-property as if that was the model all along.

    Declaration
    public static IForm<TChildModel> BeginChameleonFormFor<TParentModel, TChildModel>(this IHtmlHelper<TParentModel> helper, Expression<Func<TParentModel, TChildModel>> formFor, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType? enctype = default(EncType? ), bool? outputAntiforgeryToken = default(bool? ))
    Parameters
    Type Name Description
    Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TParentModel> helper

    The HTML Helper for the current view

    System.Linq.Expressions.Expression<System.Func<TParentModel, TChildModel>> formFor

    A lambda expression identifying the sub-property to construct the form for

    System.String action

    The action the form should submit to

    Microsoft.AspNetCore.Mvc.Rendering.FormMethod method

    The HTTP method the form submission should use

    HtmlAttributes htmlAttributes

    Any HTML attributes the form should use

    System.Nullable<EncType> enctype

    The encoding type the form submission should use

    System.Nullable<System.Boolean> outputAntiforgeryToken

    Whether or not to output an antiforgery token in the form; defaults to null which will output a token if the method isn't GET

    Returns
    Type Description
    IForm<TChildModel>

    A Form<TModel> object with an instance of the default form template renderer.

    Type Parameters
    Name Description
    TParentModel

    The model type of the view

    TChildModel

    The model type of the sub-property to construct the form for

    Examples

    @using (var f = Html.BeginChameleonFormFor(m => m.Subproperty, ...)) { ... }

    | Improve this Doc View Source

    PartialForAsync<TModel, TPartialModel>(IForm<TModel>, Expression<Func<TModel, TPartialModel>>, String)

    Renders the given partial in the context of the given property. Use PartialFor(m => m, ...) pr Partial(...) to render a partial for the model itself rather than a child property.

    Declaration
    public static Task<IHtmlContent> PartialForAsync<TModel, TPartialModel>(this IForm<TModel> form, Expression<Func<TModel, TPartialModel>> partialModelProperty, string partialViewName)
    Parameters
    Type Name Description
    IForm<TModel> form

    The form

    System.Linq.Expressions.Expression<System.Func<TModel, TPartialModel>> partialModelProperty

    The property to use for the partial model

    System.String partialViewName

    The name of the partial view to render

    Returns
    Type Description
    System.Threading.Tasks.Task<Microsoft.AspNetCore.Html.IHtmlContent>

    The HTML for the rendered partial

    Type Parameters
    Name Description
    TModel

    The form model type

    TPartialModel

    The type of the model property to use for the partial model

    • Improve this Doc
    • View Source
    Back to top © Copyright 2012-2020 MRCollective, Rob Moore, Matt Davies and the contributors to ChameleonForms.