示例#1
0
        public static string MakeActiveClass(this UrlHelper urlHelper, ActionResult controller)
        {
            string result = null;

            if (
                (controller.GetT4MVCResult().Controller == urlHelper.RequestContext.RouteData.Values["controller"].ToString()) &&
                (controller.GetT4MVCResult().Action == urlHelper.RequestContext.RouteData.Values["action"].ToString())
                )
            {
                result = "active";;
            }

            return result;
        }
        /// <summary>
        /// Creates a Navigation action link inside an li tag that highlights based on which page you're on.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="linkText">The link text.</param>
        /// <param name="actionResult">The action result.</param>
        /// <returns></returns>
        public static MvcHtmlString NavActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult actionResult)
        {
            var result = actionResult.GetT4MVCResult();

            var li = new TagBuilder("li");

            // create anchor tag
            var anchor = HtmlHelper.GenerateLink(
                    htmlHelper.ViewContext.RequestContext,
                    RouteTable.Routes,
                    linkText,
                    "",
                    result.Action,
                    result.Controller,
                    result.RouteValueDictionary,
                    null);

            // add anchor tag to li tag
            li.InnerHtml = anchor;

            // get the route data
            var controller = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue as string;
            var action = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("action").RawValue as string;
            if (result.Action == action && result.Controller == controller)
            {
                li.MergeAttribute("class", "active");
            }

            return MvcHtmlString.Create(li.ToString());
        }
示例#3
0
        public static ActionResult RedirectToLocal(this Controller controller, ActionResult action)
        {
            if (action != null && controller.Url.IsLocalUrl(controller.Url.Action(action)))
                return new RedirectToRouteResult(action.GetT4MVCResult().RouteValueDictionary);

            return new RedirectToRouteResult(MVC.Home.Index().GetT4MVCResult().RouteValueDictionary);
        }
示例#4
0
        public static ActionResult RedirectToAction(this Controller controller, ActionResult result, string urlFragment)
        {
            var callInfo = result.GetT4MVCResult();

            if (!string.IsNullOrWhiteSpace(urlFragment))
            {
                var url = UrlHelper.GenerateUrl(null, null, null, callInfo.RouteValueDictionary, RouteTable.Routes, controller.HttpContext.Request.RequestContext, false);

                url = string.Concat(url, "#", urlFragment);

                return new RedirectResult(url, false);
            }
            else
            {
                return new RedirectToRouteResult(callInfo.RouteValueDictionary);
            }
        }
示例#5
0
 public static string RouteUrl(this UrlHelper urlHelper, string routeName, ActionResult result, string protocol, string hostName)
 {
     return urlHelper.RouteUrl(routeName, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName);
 }
 /// <summary>
 /// Begins a new action link.  For use in a using statement, allowing other code inside the tag.
 /// </summary>
 /// <param name="htmlHelper">The class being extended with this method.</param>
 /// <param name="result">An IT4MVCActionResult from a T4 MVC action method used to help build urls.</param>
 /// <param name="htmlAttributes">A dictionary with name and value pairs.</param>
 /// <returns></returns>
 public static MvcTag BeginActionLink(this HtmlHelper htmlHelper, ActionResult result, IDictionary<string, object> htmlAttributes)
 {
     var callInfo = result.GetT4MVCResult();
     return htmlHelper.BeginActionLink(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary, htmlAttributes);
 }
示例#7
0
 public static MvcForm BeginForm(this HtmlHelper htmlHelper, ActionResult result, FormMethod formMethod, IDictionary<string, object> htmlAttributes)
 {
     var callInfo = result.GetT4MVCResult();
     return htmlHelper.BeginForm(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary, formMethod, htmlAttributes);
 }
示例#8
0
 public static MvcForm BeginForm(this AjaxHelper ajaxHelper, ActionResult result, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
 {
     var callInfo = result.GetT4MVCResult();
     return ajaxHelper.BeginForm(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary, ajaxOptions, htmlAttributes);
 }
示例#9
0
 public static MvcHtmlString Action(this HtmlHelper htmlHelper, ActionResult result)
 {
     var callInfo = result.GetT4MVCResult();
     return htmlHelper.Action(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary);
 }
示例#10
0
 public static string RouteUrl(this UrlHelper urlHelper, string routeName, ActionResult result, string protocol, string hostName)
 {
     return(urlHelper.RouteUrl(routeName, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName));
 }
示例#11
0
 public static string SecureAction(this UrlHelper urlHelper, ActionResult result, string protocol = null, string hostName = null)
 {
     return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName));
 }
示例#12
0
        public static MvcHtmlString SecureAction(this HtmlHelper htmlHelper, ActionResult result)
        {
            var callInfo = result.GetT4MVCResult();

            return(htmlHelper.Action(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary));
        }
示例#13
0
        public static void RenderSecureAction(this HtmlHelper htmlHelper, ActionResult result)
        {
            var callInfo = result.GetT4MVCResult();

            htmlHelper.RenderAction(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary);
        }
示例#14
0
        public static MvcForm SecureBeginForm(this HtmlHelper htmlHelper, ActionResult result, FormMethod formMethod, IDictionary <string, object> htmlAttributes)
        {
            var callInfo = result.GetT4MVCResult();

            return(htmlHelper.BeginForm(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary, formMethod, htmlAttributes));
        }
示例#15
0
 /// <summary>
 /// Generates an anchor tag (link) with an image inside such that the image when clicked follows the specified MVC route.
 /// </summary>
 /// <param name="helper">The class being extended with this method.</param>
 /// <param name="result">An IT4MVCActionResult from a T4 MVC action method used to help build urls.</param>
 /// <param name="imageFileName">The file name of the image including full relative path.  Recommend coming from T4MVC Links property.</param>
 /// <param name="anchorHtmlAttributes">A dynamic object with name and value pairs for the anchor tag.  Example:  new {data-custom1="abc", @class="large"}</param>
 /// <param name="imageHtmlAttributes">A dynamic object with name and value pairs for the image tag.  Example:  new {data-custom1="abc", @class="large"}</param>
 /// <returns></returns>
 public static MvcHtmlString ActionImageTag(this HtmlHelper helper, ActionResult result, string imageFileName, object anchorHtmlAttributes, object imageHtmlAttributes)
 {
     IT4MVCActionResult t4 = result.GetT4MVCResult();
     return ActionImageTag(helper, t4.Action, t4.Controller, imageFileName, t4.RouteValueDictionary, anchorHtmlAttributes, imageHtmlAttributes);
 }
示例#16
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes, string protocol = null, string hostName = null, string fragment = null) {
     return htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
 }
示例#17
0
 public static void RenderAction(this HtmlHelper htmlHelper, ActionResult result)
 {
     var callInfo = result.GetT4MVCResult();
     htmlHelper.RenderAction(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary);
 }
示例#18
0
        public static MvcForm SecureBeginForm(this AjaxHelper ajaxHelper, ActionResult result, AjaxOptions ajaxOptions, IDictionary <string, object> htmlAttributes)
        {
            var callInfo = result.GetT4MVCResult();

            return(ajaxHelper.BeginForm(callInfo.Action, callInfo.Controller, callInfo.RouteValueDictionary, ajaxOptions, htmlAttributes));
        }
示例#19
0
 public static string Action(this UrlHelper urlHelper, ActionResult result, string protocol = null, string hostName = null)
 {
     return urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName);
 }
示例#20
0
 public static RouteValueDictionary GetRouteValueDictionary(this ActionResult result)
 {
     return(result.GetT4MVCResult().RouteValueDictionary);
 }
示例#21
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary<string, object> htmlAttributes, string protocol, string hostName, string fragment)
 {
     return htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes);
 }
示例#22
0
 public static MvcHtmlString SecureActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary <string, object> htmlAttributes, string protocol, string hostName, string fragment)
 {
     return(htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes));
 }
示例#23
0
 protected RedirectToRouteResult RedirectToActionPermanent(ActionResult result)
 {
     var callInfo = result.GetT4MVCResult();
     return RedirectToRoutePermanent(callInfo.RouteValueDictionary);
 }
示例#24
0
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes, string protocol = null, string hostName = null, string fragment = null)
 {
     return(htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
 }