예제 #1
0
        public static MvcForm BeginForm <T>(this HtmlHelper html, Expression <Func <T, object> > expression, FormMethod formMethod = FormMethod.Post, object htmlAttributes = null) where T : ControllerBase
        {
            var controllerName       = ActionExpressionHelper.GetControllerNameFromExpression(expression);
            var actionName           = ActionExpressionHelper.GetActionNameFromExpression(expression);
            var routeValueDictionary = ActionExpressionHelper.GetRouteValuesFromExpression(expression);

            return(html.BeginForm(actionName, controllerName, routeValueDictionary, formMethod, htmlAttributes?.ToDictionary()));
        }
예제 #2
0
        public static MvcHtmlString ActionLink <T>(this HtmlHelper html, string linkText, Expression <Func <T, object> > expression, object routeValues = null, object htmlAttributes = null) where T : ControllerBase
        {
            var controllerName       = ActionExpressionHelper.GetControllerNameFromExpression(expression);
            var actionName           = ActionExpressionHelper.GetActionNameFromExpression(expression);
            var routeValueDictionary = ActionExpressionHelper.GetRouteValuesFromExpression(expression);

            if (routeValues != null)
            {
                routeValueDictionary = new RouteValueDictionary(routeValues.ToDictionary());
            }

            return(html.ActionLink(linkText, actionName, controllerName, routeValueDictionary, htmlAttributes?.ToDictionary()));
        }
예제 #3
0
        public static void RenderAction <T>(this HtmlHelper html, Expression <Func <T, object> > expression, object routeValues = null) where T : ControllerBase
        {
            var controllerName       = ActionExpressionHelper.GetControllerNameFromExpression(expression);
            var actionName           = ActionExpressionHelper.GetActionNameFromExpression(expression);
            var routeValueDictionary = ActionExpressionHelper.GetRouteValuesFromExpression(expression);

            if (routeValues != null)
            {
                routeValueDictionary = new RouteValueDictionary(routeValues.ToDictionary());
            }

            html.RenderAction(actionName, controllerName, routeValueDictionary);
        }
예제 #4
0
        public static string Action <T>(this UrlHelper url, Expression <Func <T, object> > expression, object routeValues = null, bool includeHost = false) where T : ControllerBase
        {
            var controllerName       = ActionExpressionHelper.GetControllerNameFromExpression(expression);
            var actionName           = ActionExpressionHelper.GetActionNameFromExpression(expression);
            var routeValueDictionary = ActionExpressionHelper.GetRouteValuesFromExpression(expression);

            if (routeValues != null)
            {
                routeValueDictionary = new RouteValueDictionary(routeValues.ToDictionary());
            }

            return(url.Action(actionName, controllerName, routeValueDictionary, includeHost ? url.RequestContext?.HttpContext?.Request?.Url?.Scheme : null));
        }