Ejemplo n.º 1
0
        /// <summary>
        /// Begins a <see cref="CommandForm{T}"/>, with default <see cref="FormMethod.Post"/> as method and will autodiscover any
        /// action on the controller taking the type of <see cref="ICommand">command</see> specified.
        /// </summary>
        /// <typeparam name="T">Type of Command to create form for</typeparam>
        /// <typeparam name="TC">Type of controller holding the action to forward to</typeparam>
        /// <param name="htmlHelper">HtmlHelper to begin a command form within</param>
        /// <returns>A <see cref="CommandForm{T}"/></returns>
        public static CommandForm <T> BeginCommandForm <T, TC>(this HtmlHelper htmlHelper)
            where T : ICommand, new()
            where TC : ControllerBase
        {
            var action         = ControllerHelpers.GetActionForCommand <T, TC>();
            var controllerName = ControllerHelpers.GetControllerNameFromType <TC>();
            var command        = htmlHelper.BeginCommandForm <T>(action.Name, controllerName, FormMethod.Post, new Dictionary <string, object>());

            return(command);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Begins a <see cref="CommandForm{T}"/>, with default <see cref="FormMethod.Post"/> as method
        /// </summary>
        /// <typeparam name="T">Type of Command to create form for</typeparam>
        /// <typeparam name="TC">Type of controller holding the action to forward to</typeparam>
        /// <param name="AjaxHelper">AjaxHelper to begin a command form within</param>
        /// <param name="ajaxOptions">Ajax Options for the command form</param>
        /// <returns>A <see cref="CommandForm{T}"/></returns>
        /// <remarks>
        /// For the expression that expressed the action to use, it does not care about the parameters for the action, so these
        /// can be set to null. The expression just represents the action strongly typed.
        /// </remarks>
        public static CommandForm <T> BeginCommandForm <T, TC>(this AjaxHelper AjaxHelper, AjaxOptions ajaxOptions = null)
            where T : ICommand, new()
            where TC : ControllerBase
        {
            var action         = ControllerHelpers.GetActionForCommand <T, TC>();
            var controllerName = ControllerHelpers.GetControllerNameFromType <TC>();
            var command        = AjaxHelper.BeginCommandForm <T>(action.Name, controllerName, ajaxOptions);

            return(command);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Begins a CommandForm
        /// </summary>
        /// <typeparam name="T">Type of Command to create form for</typeparam>
        /// <typeparam name="TC">Type of controller holding the action to forward to</typeparam>
        /// <param name="htmlHelper">HtmlHelper to begin a command form within</param>
        /// <param name="expression">Expression holding information about the action on the controller to use</param>
        /// <param name="formMethod"><see cref="FormMethod"/> to use</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to be set for the element</param>
        /// <returns>A <see cref="CommandForm{T}"/></returns>
        /// <remarks>
        /// For the expression that expressed the action to use, it does not care about the parameters for the action, so these
        /// can be set to null. The expression just represents the action strongly typed.
        /// </remarks>
        public static CommandForm <T> BeginCommandForm <T, TC>(this HtmlHelper htmlHelper, Expression <Func <TC, ActionResult> > expression, FormMethod formMethod, IDictionary <string, object> htmlAttributes)
            where T : ICommand, new()
            where TC : ControllerBase
        {
            var lambda = expression as LambdaExpression;

            if (null != lambda)
            {
                var methodCallExpression = lambda.Body as MethodCallExpression;
                if (null != methodCallExpression)
                {
                    var actionName     = methodCallExpression.Method.Name;
                    var controllerName = ControllerHelpers.GetControllerNameFromType <TC>();
                    var commandForm    = BeginCommandForm <T>(htmlHelper, actionName, controllerName, formMethod, htmlAttributes);
                    return(commandForm);
                }
            }

            return(null);
        }