本文整理汇总了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 })
)
);
}
}
示例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());
}
示例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();
}
}
示例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());
}
示例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;
}
示例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());
}
示例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());
}
示例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)
));
}
示例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");
}
示例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();
}
示例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);
}
}
示例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));
}
示例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() );
}
示例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());
}
示例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();
}