当前位置: 首页>>代码示例>>C#>>正文


C# UrlHelper.Content方法代码示例

本文整理汇总了C#中System.Web.Mvc.UrlHelper.Content方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.Content方法的具体用法?C# UrlHelper.Content怎么用?C# UrlHelper.Content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.UrlHelper的用法示例。


在下文中一共展示了UrlHelper.Content方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmployeeImageRight

 public static MvcHtmlString EmployeeImageRight(this HtmlHelper helper, Employee item)
 {
     var url = new UrlHelper(helper.ViewContext.RequestContext);
     var path = HttpContext.Current.Server.MapPath("~/public/userfiles/employees/" + item.Id + ".jpg");
     if (File.Exists(path))
     {
         return MvcHtmlString.Create(
             string.Format("<a href='{3}' class='employee-photo top-photo'><img title='{1}'  src='{2}' /></a>",
                 url.Content("~/public/images/pix.gif"),
                 item.FullName,
                 url.Content("~/public/userfiles/employees/" + item.Id + ".jpg"),
                 url.Action("Card", "Employees", new { item.Id })
             )
         );
     }
     else
     {
         return MvcHtmlString.Create(
       string.Format("<a href='{3}' class='employee-photo'><img title='{1}' style='background-size: 100%;background-image: url({2})' src='{0}' /></a>",
           url.Content("~/public/images/pix.gif"),
           item.FullName,
           url.Content("~/public/images/picture_bg.jpg"),
           url.Action("Card", "Employees", new { item.Id })
       )
   );
     }
 }
开发者ID:Avimunk,项目名称:soglowek.tmgroup,代码行数:27,代码来源:EmployeesHelper.cs

示例2: UnitImage

        public static MvcHtmlString UnitImage(this HtmlHelper helper, String controller, String action, Object parameters, String src, String alt = "", String title = "")
        {
            var tagBuilder = new TagBuilder("img");
            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
            var url = urlHelper.Action(action, controller, parameters);
            var imgUrl = urlHelper.Content(src);
            var image = "";
            var html = new StringBuilder();

            // build the image tag.
            tagBuilder.MergeAttribute("src", imgUrl);
            tagBuilder.MergeAttribute("alt", alt);
            //tagBuilder.MergeAttribute("width", "100");
            //tagBuilder.MergeAttribute("height", "100");
            tagBuilder.MergeAttribute("title", title);
            image = tagBuilder.ToString(TagRenderMode.SelfClosing);

            html.Append("<a href=\"");
            html.Append(urlHelper.Content(src));
            html.Append("\">");
            html.Append(image);
            html.Append("</a>");

            return MvcHtmlString.Create(html.ToString());
        }
开发者ID:haithemaraissia,项目名称:Rental,代码行数:25,代码来源:ImageHelper.cs

示例3: PageExpander

        public static string PageExpander(this HtmlHelper htmlHelper, Node node, Node activeNode)
        {
            UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

            if (node.ChildNodes.Count > 0)
            {
                TagBuilder expanderImage = new TagBuilder("img");

                if (node.Level < 1 || (node.IsInPath(activeNode)))
                {
                    expanderImage.AddCssClass("children-visible");
                    expanderImage.Attributes.Add("src", urlHelper.Content("~/manager/Content/Images/collapse.png"));
                }
                else
                {
                    expanderImage.AddCssClass("children-hidden");
                    expanderImage.Attributes.Add("src", urlHelper.Content("~/manager/Content/Images/expand.png"));
                }
                expanderImage.Attributes.Add("alt", "toggle");
                return expanderImage.ToString();
            }
            else
            {
                TagBuilder expanderSpan = new TagBuilder("span");
                string className = "no-children";
                expanderSpan.AddCssClass(className);
                return expanderSpan.ToString();
            }
        }
开发者ID:xwyangjshb,项目名称:cuyahoga,代码行数:29,代码来源:PageAdminExtensions.cs

示例4: Menu

        public static MvcHtmlString Menu(this HtmlHelper helper, bool isMobile = false)
        {
            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
            var sb = new StringBuilder();

            if (isMobile)
            {
                sb.Append("<select onchange='location.href=this.value;'>");
                sb.Append("<option value=''></option>");
                sb.AppendFormat("<option {0} value='{1}'>{2}</option>",
                    IsCurrentPage(urlHelper.Content("~/"), HttpContext.Current.Request) ? "selected='selected'" : "",
                    urlHelper.Content("~/"), "Dashboard");
            }
            else
                sb.Append("<ul id='menu'>");
            var siteMap = new FileInfo(HttpContext.Current.Server.MapPath("~/web.sitemap"));
            if (siteMap.Exists)
            {
                var smXDoc = new XmlDocument();
                smXDoc.Load(siteMap.FullName);
                _xmlnsManager = new XmlNamespaceManager(smXDoc.NameTable);
                _xmlnsManager.AddNamespace("mi", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");

                var nodes = smXDoc.SelectNodes("/mi:siteMap/mi:siteMapNode/mi:siteMapNode", _xmlnsManager);
                WriteNodes(sb, nodes, urlHelper, isMobile);
            }
            if (isMobile)
                sb.Append("</select>");
            else
                sb.Append("</ul>");


            return new MvcHtmlString(sb.ToString());
        }
开发者ID:ThirdCornerLLC,项目名称:ThirdCorner.Base,代码行数:34,代码来源:Menu.cs

示例5: GetMenu

        public static List<Menu> GetMenu(RequestContext _context)
        {
            UrlHelper Url = new UrlHelper(_context);
            List<Menu> menus = new List<Menu>();
            Menu m1 = new Menu("a10", null, "首页", "menu-icon fa fa-home", Url.Content("~/Home/Index"));
            Menu m2 = new Menu("a11", null, "人员列表", "menu-icon fa fa-list", Url.Content("~/Human/List"));

            Menu m4 = new Menu("a15", null, "人员信息统计", "menu-icon fa fa-bar-chart-o", "#");
            m4.AddChild("a1501", "按年龄段统计", string.Empty, Url.Action("NianLing", "TongJi"));
            m4.AddChild("a1502", "按学历统计", string.Empty, Url.Action("XueLi", "TongJi"));
            m4.AddChild("a1503", "按政治面貌统计", string.Empty, Url.Action("ZhengZhi", "TongJi"));
            m4.AddChild("a1504", "按入职时间统计", string.Empty, Url.Action("RuZhi", "TongJi"));
            m4.AddChild("a1505", "按岗位统计", string.Empty, Url.Action("GangWei", "TongJi"));
            m4.AddChild("a1506", "按职称统计", string.Empty, Url.Action("ZhiCheng", "TongJi"));
            Menu m3 = new Menu("a12", null, "系统设置", "menu-icon fa fa-pencil-square-o", "#");

            m3.AddChild("a13", "数据字典栏目", string.Empty, Url.Action("Index", "DicLan"));
            m3.AddChild("a14", "数据字典", string.Empty, Url.Action("Index", "DicLan"));

            menus.Add(m1);
            menus.Add(m2);
            menus.Add(m4);
            menus.Add(m3);

            return menus;
        }
开发者ID:tomatochen,项目名称:jcshop,代码行数:26,代码来源:VTool.cs

示例6: Sidebar

        public static MvcHtmlString Sidebar(this HtmlHelper htmlHelper, UrlHelper urlHelper, IEnumerable<Category> categories, int departmentId, int viewedCategoryId = -1)
        {
            var builder = new StringBuilder();

            builder.Append("<aside class=\"pro-left\">\n<aside class=\"gray-smll\">\n<h1>Shop By Category</h1><ul>");

            foreach (var category in categories)
            {
                builder.AppendFormat(
                    "<li><a href=\"{0}\"{1}>{2}</a></li>",
                    urlHelper.Action("Index", "Department", new { DepartmentId = departmentId, CategoryId = category.Id }),
                    category.Id == viewedCategoryId ? " class=\"current\"" : "",
                    category.Name
                );
            }

            builder.Append("</ul></aside>");

            builder.AppendFormat(
                "<img src=\"{0}\" class=\"left clear\" />",
                urlHelper.Content("~/Content/images/bg-gray-smll-bot.jpg")
            );
            builder.AppendFormat(
                "<img src=\"{0}\" class=\"left clear\" />",
                urlHelper.Content("~/Content/images/img-left-smll.jpg")
            );

            builder.Append("</aside>");

            return new MvcHtmlString(builder.ToString());
        }
开发者ID:ganeshkumar-m,项目名称:ShoppingSite,代码行数:31,代码来源:HtmlHelperExtensions.cs

示例7: ReferenceBundle

        private static MvcHtmlString ReferenceBundle(HtmlHelper helper, string bundlePath, TagBuilder baseTag, string key)
        {
            var bundle = BundleTable.Bundles.GetBundleFor(bundlePath);
            if (bundle == null)
                throw new ArgumentException("Invalid Bundle Path", "bundlePath");

            var httpContext = helper.ViewContext.HttpContext;
            if (!BundleConfigurationManager.Ignore(httpContext))
            {
                baseTag.MergeAttribute(key, BundleTable.Bundles.ResolveBundleUrl(bundlePath));
                return new MvcHtmlString(baseTag.ToString());
            }

            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
            var bundleContext = new BundleContext(helper.ViewContext.HttpContext, BundleTable.Bundles, urlHelper.Content(bundlePath));
            var htmlString = new StringBuilder();

            foreach (var file in bundle.EnumerateFiles(bundleContext))
            {
                var basePath = httpContext.Server.MapPath("~/");
                if (!file.FullName.StartsWith(basePath))
                    continue;

                var relPath = urlHelper.Content("~/" + file.FullName.Substring(basePath.Length));
                baseTag.MergeAttribute(key, relPath, true);
                htmlString.AppendLine(baseTag.ToString());
            }

            return new MvcHtmlString(htmlString.ToString());
        }
开发者ID:kouweizhong,项目名称:MvcBundleConfig,代码行数:30,代码来源:HtmlHelperExtensions.cs

示例8: EmplloyeePhoto

		public static MvcHtmlString EmplloyeePhoto(this HtmlHelper helper, EmployeePhoto photo) {
			if (photo == null)
				return MvcHtmlString.Empty;

			var url = new UrlHelper(helper.ViewContext.RequestContext);

			return MvcHtmlString.Create(string.Format("<a rel='gallery' class='employeephoto-photo' href='{0}'><img src='{1}'/></a>",
				url.Content("~/public/UserFiles/employeephotos/big/" + photo.FileName),
				url.Content("~/public/UserFiles/employeephotos/small/" + photo.FileName)
			));
		}
开发者ID:Avimunk,项目名称:soglowek.tmgroup,代码行数:11,代码来源:EmployeePhotosHelper.cs

示例9: GlobalJsVars

        /// <summary>
        /// Returns a string containing Javascript 'constants' for the site.
        /// </summary>
        public ActionResult GlobalJsVars()
        {
            UrlHelper helper = new UrlHelper(HttpContext.Request.RequestContext);

            StringBuilder builder = new StringBuilder();
            builder.AppendLine(string.Format("var SPRUCE_SCRIPTPATH = '{0}';", helper.Content("~/Assets/Scripts/")));
            builder.AppendLine(string.Format("var SPRUCE_CSSPATH = '{0}';", helper.Content("~/Assets/Css/")));
            builder.AppendLine(string.Format("var SPRUCE_IMAGEPATH = '{0}';", helper.Content("~/Assets/Images/")));

            return Content(builder.ToString(), "text/javascript");
        }
开发者ID:yetanotherchris,项目名称:spruce,代码行数:14,代码来源:HomeController.cs

示例10: GetSocialImage

        private static string GetSocialImage(this HtmlHelper htmlHelper, SocialFeature feature)
        {
            var img = new TagBuilder("img");

            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

            img.MergeAttribute("class", "pop rollover");
            img.MergeAttribute("src", urlHelper.Content(string.Format("~/Content/Images/social_icons/{0}.png", feature.FeatureImagePart)));
            img.MergeAttribute("data-rollover", urlHelper.Content(string.Format("~/Content/Images/social_icons/{0}-hover.png", feature.FeatureImagePart)));
            img.MergeAttribute("alt", feature.FeatureImagePart);

            return MvcHtmlString.Create(img.ToString()).ToHtmlString();
        }
开发者ID:rinckd,项目名称:sblog.net,代码行数:13,代码来源:SocialFeaturesHtmlHelper.cs

示例11: ImageUrlFor

 public static string ImageUrlFor(this HtmlHelper helper, string contentUrl)
 {
     // Put some caching logic here if you want it to perform better
     UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
     if (!File.Exists(helper.ViewContext.HttpContext.Server.MapPath(contentUrl)))
     {
         return urlHelper.Content("~/Content/images/none.jpg");
     }
     else
     {
         return urlHelper.Content(contentUrl);
     }
 }
开发者ID:tuanzhang7,项目名称:acct.aspnet,代码行数:13,代码来源:HTMLHelper.cs

示例12: CssBuilder

 public static IHtmlString CssBuilder(this HtmlHelper htmlHelper, UrlHelper url, string value, bool removeProtocol = true)
 {
     TagBuilder builder = new TagBuilder("link");
     if (GlobalConfig.IsAssetsEnabled)
     {
         string protocol = "^http[s]*:";
         builder.Attributes.Add("href", url.Content(String.Format("{0}/content/{1}", removeProtocol ? Regex.Replace(GlobalConfig.AssetsBaseUrl, protocol, String.Empty) : GlobalConfig.AssetsBaseUrl, value)));
     }
     else
         builder.Attributes.Add("href", url.Content("~/Content/" + value));
     builder.Attributes.Add("rel", "stylesheet");
     builder.Attributes.Add("type", "text/css");
     return htmlHelper.Raw(builder.ToString(TagRenderMode.SelfClosing));
 }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:14,代码来源:MyHtmlHelper.cs

示例13: Script

        public static MvcHtmlString Script(this HtmlHelper helper, string scriptFilename)
        {
            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);

            TagBuilder builder = new TagBuilder("script");

            if (Path.GetExtension(scriptFilename) == ".js") {
                builder.Attributes.Add("src", urlHelper.Content("~/Scripts/" + scriptFilename));
            } else {
                builder.Attributes.Add("src", urlHelper.Content("~/Scripts/" + scriptFilename + ".js"));
            }

            return MvcHtmlString.Create( builder.ToString() );
        }
开发者ID:jwwishart,项目名称:Catechize,代码行数:14,代码来源:HtmlHelperExtensions.cs

示例14: JsBuilder

 public static IHtmlString JsBuilder(this HtmlHelper htmlHelper, UrlHelper url, string value, bool removeProtocol = true)
 {
     TagBuilder builder = new TagBuilder("script");
     //builder.Attributes.Add("src", url.Content("~/Scripts/" + value));
     if (GlobalConfig.IsAssetsEnabled)
     {
         string protocol = "^http[s]*:";
         builder.Attributes.Add("src", url.Content(String.Format("{0}/scripts/{1}", removeProtocol ? Regex.Replace(GlobalConfig.AssetsBaseUrl, protocol, String.Empty) : GlobalConfig.AssetsBaseUrl, value)));
     }
     else
         builder.Attributes.Add("src", url.Content("~/Scripts/" + value));
     builder.Attributes.Add("type", "text/javascript");
     builder.Attributes.Add("language", "JavaScript");
     return htmlHelper.Raw(builder.ToString());
 }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:15,代码来源:MyHtmlHelper.cs

示例15: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext) {
            HttpSessionStateBase session = filterContext.HttpContext.Session;

            Services.User user = (Services.User)session[Constants.SESSION_USER];
            if (user != null) {
                return;
            }

            String urlFrom = String.Empty;
            UrlHelper url;

            //send them off to the login page
            url = new UrlHelper(filterContext.RequestContext);
            urlFrom = filterContext.Controller.ControllerContext.RequestContext.HttpContext.Request.RawUrl;
            if (!String.IsNullOrEmpty(urlFrom)) {
                urlFrom = String.Format("?{0}", urlFrom);
            }
            var loginUrl = url.Content(String.Format("~/LogIn{0}", urlFrom));
            session.RemoveAll();
            session.Clear();
            session.Abandon();

            filterContext.HttpContext.Response.StatusCode = 403;
            filterContext.HttpContext.Response.Redirect(loginUrl, false);
            filterContext.Result = new EmptyResult();
        }
开发者ID:ValGikhman,项目名称:MenuzRus.com,代码行数:26,代码来源:CheckUserSessionAttribute.cs


注:本文中的System.Web.Mvc.UrlHelper.Content方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。