コード例 #1
0
ファイル: Form.cs プロジェクト: rsaladrigas/ChameleonForms
 /// <summary>
 /// Constructs a <see cref="Form{TModel}"/> object with the default Chameleon form template renderer.
 /// </summary>
 /// <example>
 /// @using (var f = Html.BeginChameleonForm(...)) {
 ///     ...
 /// }
 /// </example>
 /// <typeparam name="TModel">The view model type for the current view</typeparam>
 /// <param name="helper">The HTML Helper for the current view</param>
 /// <param name="action">The action the form should submit to</param>
 /// <param name="method">The HTTP method the form submission should use</param>
 /// <param name="htmlAttributes">Any HTML attributes the form should use</param>
 /// <param name="enctype">The encoding type the form submission should use</param>
 /// <returns>A <see cref="Form{TModel}"/> object with an instance of the default form template renderer.</returns>
 public static IForm <TModel> BeginChameleonForm <TModel>(this HtmlHelper <TModel> helper, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType?enctype = null)
 {
     return(new Form <TModel>(helper, FormTemplate.Default, action, method, htmlAttributes, enctype));
 }
コード例 #2
0
ファイル: Form.cs プロジェクト: rsaladrigas/ChameleonForms
 /// <summary>
 /// Construct a Chameleon Form.
 /// Note: Contains a call to the virtual method Write.
 /// </summary>
 /// <param name="helper">The HTML Helper for the current view</param>
 /// <param name="template">A template renderer instance to use to render the form</param>
 /// <param name="action">The action the form should submit to</param>
 /// <param name="method">The HTTP method the form submission should use</param>
 /// <param name="htmlAttributes">Any HTML attributes the form should use expressed as an anonymous object</param>
 /// <param name="enctype">The encoding type the form submission should use</param>
 public Form(HtmlHelper <TModel> helper, IFormTemplate template, string action, FormMethod method, HtmlAttributes htmlAttributes, EncType?enctype)
 {
     HtmlHelper = helper;
     Template   = template;
     // ReSharper disable DoNotCallOverridableMethodsInConstructor
     // Write method is virtual to allow it to be mocked for testing
     Write(Template.BeginForm(action, method, htmlAttributes, enctype));
     // ReSharper restore DoNotCallOverridableMethodsInConstructor
 }
コード例 #3
0
        /// <summary>
        /// Constructs a <see cref="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.
        /// </summary>
        /// <example>
        /// @using (var f = Html.BeginChameleonFormFor(new AnotherModelType(), ...)) {
        ///     ...
        /// }
        /// @using (var f = Html.BeginChameleonFormFor(default(AnotherModelType), ...)) {
        ///     ...
        /// }
        /// </example>
        /// <remarks>
        /// This can also be done using the For() extension method and just a type:
        /// @using (var f = Html.For&lt;AnotherModelType&gt;().BeginChameleonForm(...)) {
        ///     ...
        /// }
        /// </remarks>
        /// <typeparam name="TOriginalModel">The model type of the view</typeparam>
        /// <typeparam name="TNewModel">The model type of the sub-property to construct the form for</typeparam>
        /// <param name="helper">The HTML Helper for the current view</param>
        /// <param name="model">The model to use for the form</param>
        /// <param name="action">The action the form should submit to</param>
        /// <param name="method">The HTTP method the form submission should use</param>
        /// <param name="htmlAttributes">Any HTML attributes the form should use</param>
        /// <param name="enctype">The encoding type the form submission should use</param>
        /// <returns>A <see cref="Form{TModel}"/> object with an instance of the default form template renderer.</returns>
        public static IForm <TNewModel> BeginChameleonFormFor <TOriginalModel, TNewModel>(this HtmlHelper <TOriginalModel> helper, TNewModel model, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType?enctype = null)
        {
            var childHelper = helper.For(model);

            return(new Form <TNewModel>(childHelper, FormTemplate.Default, action, method, htmlAttributes, enctype));
        }
コード例 #4
0
        /// <summary>
        /// Constructs a <see cref="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.
        /// </summary>
        /// <example>
        /// @using (var f = Html.BeginChameleonFormFor(m => m.Subproperty, ...)) {
        ///     ...
        /// }
        /// </example>
        /// <typeparam name="TParentModel">The model type of the view</typeparam>
        /// <typeparam name="TChildModel">The model type of the sub-property to construct the form for</typeparam>
        /// <param name="helper">The HTML Helper for the current view</param>
        /// <param name="formFor">A lambda expression identifying the sub-property to construct the form for</param>
        /// <param name="action">The action the form should submit to</param>
        /// <param name="method">The HTTP method the form submission should use</param>
        /// <param name="htmlAttributes">Any HTML attributes the form should use</param>
        /// <param name="enctype">The encoding type the form submission should use</param>
        /// <returns>A <see cref="Form{TModel}"/> object with an instance of the default form template renderer.</returns>
        public static IForm <TChildModel> BeginChameleonFormFor <TParentModel, TChildModel>(this HtmlHelper <TParentModel> helper, Expression <Func <TParentModel, TChildModel> > formFor, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType?enctype = null)
        {
            var childHelper = helper.For(formFor, bindFieldsToParent: false);

            return(new Form <TChildModel>(childHelper, FormTemplate.Default, action, method, htmlAttributes, enctype));
        }
コード例 #5
0
ファイル: Form.cs プロジェクト: girish66/ChameleonForms
 /// <summary>
 /// Construct a Chameleon Form.
 /// Note: Contains a call to the virtual method Write.
 /// </summary>
 /// <param name="helper">The HTML Helper for the current view</param>
 /// <param name="template">A template renderer instance to use to render the form</param>
 /// <param name="action">The action the form should submit to</param>
 /// <param name="method">The HTTP method the form submission should use</param>
 /// <param name="htmlAttributes">Any HTML attributes the form should use expressed as an anonymous object</param>
 /// <param name="enctype">The encoding type the form submission should use</param>
 /// <param name="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</param>
 public Form(IHtmlHelper <TModel> helper, IFormTemplate template, string action, FormMethod method, HtmlAttributes htmlAttributes, EncType?enctype, bool?outputAntiforgeryToken)
 {
     _outputAntiforgeryToken = outputAntiforgeryToken ?? method != FormMethod.Get;
     helper.ViewData[Constants.ViewDataFormKey] = this;
     HtmlHelper = helper;
     Template   = template;
     // ReSharper disable DoNotCallOverridableMethodsInConstructor
     // Write method is virtual to allow it to be mocked for testing
     Write(Template.BeginForm(action, method, htmlAttributes, enctype));
     // ReSharper restore DoNotCallOverridableMethodsInConstructor
 }
コード例 #6
0
ファイル: Form.cs プロジェクト: girish66/ChameleonForms
        /// <summary>
        /// Constructs a <see cref="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.
        /// </summary>
        /// <example>
        /// @using (var f = Html.BeginChameleonFormFor(new AnotherModelType(), ...)) {
        ///     ...
        /// }
        /// @using (var f = Html.BeginChameleonFormFor(default(AnotherModelType), ...)) {
        ///     ...
        /// }
        /// </example>
        /// <remarks>
        /// This can also be done using the For() HTML helper extension method and just a type:
        /// @using (var f = Html.For&lt;AnotherModelType&gt;().BeginChameleonForm(...)) {
        ///     ...
        /// }
        /// </remarks>
        /// <typeparam name="TOriginalModel">The model type of the view</typeparam>
        /// <typeparam name="TNewModel">The model type of the sub-property to construct the form for</typeparam>
        /// <param name="helper">The HTML Helper for the current view</param>
        /// <param name="model">The model to use for the form</param>
        /// <param name="action">The action the form should submit to</param>
        /// <param name="method">The HTTP method the form submission should use</param>
        /// <param name="htmlAttributes">Any HTML attributes the form should use</param>
        /// <param name="enctype">The encoding type the form submission should use</param>
        /// <param name="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</param>
        /// <returns>A <see cref="Form{TModel}"/> object with an instance of the default form template renderer.</returns>
        public static IForm <TNewModel> BeginChameleonFormFor <TOriginalModel, TNewModel>(this IHtmlHelper <TOriginalModel> helper, TNewModel model, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType?enctype = null, bool?outputAntiforgeryToken = null)
        {
            var childHelper = helper.For(model);

            return(new Form <TNewModel>(childHelper, helper.GetDefaultFormTemplate(), action, method, htmlAttributes, enctype, outputAntiforgeryToken));
        }
コード例 #7
0
ファイル: Form.cs プロジェクト: girish66/ChameleonForms
 /// <summary>
 /// Constructs a <see cref="Form{TModel}"/> object with the default ChameleonForms template renderer.
 /// </summary>
 /// <example>
 /// @using (var f = Html.BeginChameleonForm(...)) {
 ///     ...
 /// }
 /// </example>
 /// <typeparam name="TModel">The view model type for the current view</typeparam>
 /// <param name="helper">The HTML Helper for the current view</param>
 /// <param name="action">The action the form should submit to</param>
 /// <param name="method">The HTTP method the form submission should use</param>
 /// <param name="htmlAttributes">Any HTML attributes the form should use</param>
 /// <param name="enctype">The encoding type the form submission should use</param>
 /// <param name="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</param>
 /// <returns>A <see cref="Form{TModel}"/> object with an instance of the default form template renderer.</returns>
 public static IForm <TModel> BeginChameleonForm <TModel>(this IHtmlHelper <TModel> helper, string action = "", FormMethod method = FormMethod.Post, HtmlAttributes htmlAttributes = null, EncType?enctype = null, bool?outputAntiforgeryToken = null)
 {
     return(new Form <TModel>(helper, helper.GetDefaultFormTemplate(), action, method, htmlAttributes, enctype, outputAntiforgeryToken));
 }