public Line Add(MvcHtmlString label, MvcHtmlString input, bool show = true) { string html = "{0}<div class='controls controls-row'>{1}</div>"; string lbl; if (show) { if (MvcHtmlString.IsNullOrEmpty(label)) { lbl = "<label class='control-label'> </label>"; } else { lbl = label.ToString().Replace("<label ", "<label class='control-label' "); } html = string.Format(html, lbl, input.ToString()); //TagBuilder l = new TagBuilder("div"); //l.AddCssClass("control-group"); //l.InnerHtml += MvcHtmlString.IsNullOrEmpty(label) ? "<label> </label>" : label.ToString(); //l.InnerHtml += input.ToString(); p.InnerHtml += html; } return this; }
protected void AppendMvcHtmlString(MvcHtmlString htmlString) { if (htmlString != null) { this.htmlTextWriter.Write(htmlString.ToString()); } }
public FormRow AddToRight(MvcHtmlString markup) { if (markup != null) { return AddToRight(markup.ToString()); } return this; }
public void HighlightPattern_Test() { HtmlHelper helper = null; string target = "Spam string spam with spAm pattern sPAm"; string pattern = "spam"; string highlightTag = "i"; MvcHtmlString expected = new MvcHtmlString("<i>Spam</i> string <i>spam</i> with <i>spAm</i> pattern <i>sPAm</i>"); MvcHtmlString actual; actual = HighlightPatternExtension.HighlightPattern(helper, target, pattern, highlightTag); Assert.AreEqual(expected.ToString(), actual.ToString()); }
public static MvcHtmlString CustomTruncate(this HtmlHelper x, MvcHtmlString s, int nbr) { var chaine = WebUtility.HtmlDecode(s.ToString()); if (chaine.Length > nbr) { return MvcHtmlString.Create( String.Format("{0}...", chaine.Substring(0,nbr))); } else { return s; } }
public void Test(string currentDomain, string expectedToken) { var logger = new FakeLogger(); var serializer = new FakeDomainSerializer(); var check = new StaticDomainCheck(logger, serializer); var tokenizer = new FakeTokenizer(); var generator = new AntiforgeryTokenGenerator(check, tokenizer, currentDomain); var result = generator.GetAntiForgeryToken(); var expected = new MvcHtmlString(expectedToken); Assert.Equal(expected.ToString(), result.ToString()); }
private static MvcHtmlString NavigationItem(this HtmlHelper htmlHelper, string controllerName, MvcHtmlString innerHtml) { var tag = new TagBuilder("li"); var isCurrent = htmlHelper.IsCurrentController(controllerName); if (isCurrent) { tag.AddCssClass("active"); } tag.InnerHtml = innerHtml.ToString(); return MvcHtmlString.Create(tag.ToString()); }
public void RegisterScript_TwoTimes_NoDuplicateRegistrations() { var dummyHttpContext = new DummyHttpContext(); var dummyViewContext = new ViewContext(); dummyViewContext.HttpContext = dummyHttpContext; var dummyViewDataContainer = (IViewDataContainer) new ViewPage(); var script = "Mvc/Scripts/Designer/modal-dialog.js"; var htmlHelper = new System.Web.Mvc.HtmlHelper(dummyViewContext, dummyViewDataContainer); System.Web.Mvc.MvcHtmlString result = htmlHelper.Script(script); Assert.AreEqual(result.ToString(), string.Format(System.Globalization.CultureInfo.InvariantCulture, "<script src=\"{0}\" type=\"text/javascript\"></script>", script)); result = htmlHelper.Script(script); Assert.AreEqual(result, System.Web.Mvc.MvcHtmlString.Empty); }
public static TimeToRead CalculateTimeToRead(MvcHtmlString body) { if (body == null) return TimeToRead.Empty; var bodyAsString = body.ToString(); var parts = bodyAsString.Split(' '); var wordCount = parts.Length; var rate = wordCount / 200.0; var minutes = (int)rate; var seconds = (rate - minutes) * 0.6; var minutesAndSeconds = minutes + seconds; var timeToReadInMinutes = (int)Math.Ceiling(minutesAndSeconds); return new TimeToRead { TimeToReadInMinutes = timeToReadInMinutes, WordCount = wordCount }; }
/// <summary> /// /// </summary> /// <param name="iconClass"></param> /// <param name="isFixed"></param> /// <param name="items"></param> /// <returns></returns> public MvcHtmlString Breadcrumbs(string iconClass, List<Nav> items, bool isFixed = false, MvcHtmlString append = null) { if (items == null || items.Count == 0) throw new ArgumentException("data 参数不能为空!"); var html = new StringBuilder(); html.AppendFormat("<div class=\"breadcrumbs{0}\" id=\"breadcrumbs\">", isFixed ? " breadcrumbs-fixed" : string.Empty); html.Append("<script>try { ace.settings.check('breadcrumbs', 'fixed') } catch (e) { }</script>"); html.Append("<ul class=\"breadcrumb\">"); var flag = 0; var icon = string.Format("<i class=\"ace-icon fa {0}\"></i>", iconClass); foreach (var item in items) { if (flag == items.Count - 1) html.AppendFormat("<li class=\"active\"> {0} {1}</li>", flag == 0 ? icon : string.Empty, item.Text); else html.AppendFormat("<li>{0}<a href = \"{1}\" > {2} </a></li>", flag == 0 ? icon : string.Empty, item.Url, item.Text); flag++; } html.Append("</ul>"); if (append != null) html.Append(append.ToString()); html.Append("</div>"); return MvcHtmlString.Create(html.ToString()); }
public static MvcHtmlString BootstrapControlGroup(this HtmlHelper htmlHelper, MvcHtmlString htmlLabel, MvcHtmlString htmlEditor, MvcHtmlString htmlValidator, MvcHtmlString htmlHelpText) { TagBuilder builder = new TagBuilder("div"); builder.AddCssClass("control-group"); builder.InnerHtml += htmlLabel; TagBuilder div = new TagBuilder("div"); div.AddCssClass("controls"); div.InnerHtml += htmlEditor; div.InnerHtml += htmlValidator; if (htmlHelpText != null && !string.IsNullOrEmpty(htmlHelpText.ToString())) { TagBuilder p = new TagBuilder("p"); p.AddCssClass("help-block"); p.InnerHtml += htmlHelpText; div.InnerHtml += p; } builder.InnerHtml += div; return MvcHtmlString.Create(builder.ToString()); }
public string H(MvcHtmlString value) { return value == null ? null : value.ToString(); }
private static MvcHtmlString ReplaceGuidWithRealText(string linkText, MvcHtmlString linkString) { return new MvcHtmlString(linkString.ToString().Replace(guid, linkText)); }
public string H(MvcHtmlString value) { return value.ToString(); }
public ActionResult OperateGuanJianZiHuiFu(FormCollection fc, GuanJianZiHuiFuContract pc, string id, string url) { #region 绑定关键字回复内容所属的关键字 List<GuanJianZiHuiFuTypeContract> list = new List<GuanJianZiHuiFuTypeContract>(); //获取所有的关键字类型 List<GuanJianZiHuiFuType> dsGJZType = hfs.GetAllGJZType(); foreach (var item in dsGJZType) { GuanJianZiHuiFuTypeContract emp = new GuanJianZiHuiFuTypeContract(); emp.trueId = Convert.ToInt32(item.trueId); emp.name = item.name; list.Add(emp); } ViewData["gjz"] = new SelectList(list, "trueId", "name"); #endregion #region 绑定企业 List<employeeInfo> listEmp = null; if ((Session["user"] as UsersContract).RoleID == 1) { #region 系统管理员 获取所有企业信息 listEmp = gs.GetAllEmp(); #endregion } else { #region 获取自己的关键字 listEmp = gs.GetAllEmp((Session["user"] as UsersContract).EId); #endregion } //获取所有的企业 ViewData["emp"] = new SelectList(listEmp, "Eid", "wxName"); #endregion var countent = new MvcHtmlString(pc.content); pc.content = countent.ToString(); //图文图片 string img = fc["willUploadImg"]; //判断要添加的关键字是否已经存在 //if (hfs.IsExists(pc.content, pc.gjzId.ToString(), id)) //{ // //执行失败信息 // ViewData["msg"] = "要添加的回复内容已经存在,请先确认!"; // //失败视图 // return View("Error"); //} //else //{ pc.time = DateTime.Now.ToString(); pc.img = img; switch (ModelState.IsValid) { case true: //如果要修改的编号为null,则为添加回复信息操作 if (id != null && id == "0") { if (hfs.AddGuanJianZiHuiFu(pc) > 0) { //成功后要跳转的路径(如果无须跳转,直接留在当前页面,不写即可) ViewData["url"] = new UrlHelper(Request.RequestContext).Action("GuanJianZiHuiFuMain"); //执行成功信息 ViewData["msg"] = "添加回复内容成功!"; //成功视图 return View("Success"); } else { //执行成功信息 ViewData["msg"] = "添加回复内容失败!"; return View("Error"); } } else { pc.gjzId = int.Parse(fc["gjzId"]); if (hfs.UpdateGuanJianZiHuiFu(pc) > 0) { //执行成功信息 ViewData["msg"] = "修改回复内容成功!"; //成功后要跳转的路径(如果无须跳转,直接留在当前页面,不写即可) ViewData["url"] = new UrlHelper(Request.RequestContext).Action("GuanJianZiHuiFuMain"); //成功视图 return View("Success"); } else { ViewData["msg"] = "修改关回复内容失败!"; return View("Error"); } } default: ViewBag.pTitle = "添加回复内容信息"; return View(new GuanJianZiHuiFuContract()); //} } }
private void PageLinkAssert(MvcHtmlString htmlString) { Assert.AreEqual(htmlString.ToString(), @"<a href=""Page1"">1</a>" + @"<a class=""selected"" href=""Page2"">2</a>" + @"<a href=""Page3"">3</a>"); }
private static void Add(HtmlHelper helper, string key, MvcHtmlString text) { if (text != null) { Get(helper, key).Add(text.ToString()); } }
public FormRow AddToLeft(MvcHtmlString markup) { return AddToLeft(markup.ToString()); }
private static void AddUnique(HtmlHelper helper, string key, MvcHtmlString text) { if (text != null) { AddUnique(helper, key, text.ToString()); } }
/// <summary> /// Adds the specified self. /// </summary> /// <param name="self">The self.</param> /// <param name="other">The other.</param> /// <param name="addSpace">if set to <c>true</c> [add space].</param> /// <returns></returns> public static MvcHtmlString Add(this MvcHtmlString self, MvcHtmlString other, bool addSpace = false) { return(self.Add(other.ToString(), addSpace)); }
/// <summary> /// Looks for Html links in the passed string and turns each relative or absolute url into a fully-qualified url path using the Https protocol. /// </summary> /// <param name="text">The url to make fully-qualified. Ex: <a href="Home/About">Blah</a></param> /// <returns>The absolute url plus server, & port using the Https protocol. Ex: <a href="https://localhost:1234/Home/About">Blah</a></returns> public virtual MvcHtmlString ToSslLink(MvcHtmlString text) { // TODO: This won't work with .NET 4 if (!UseSsl()) return text; return MvcHtmlString.Create(ToFullyQualifiedLink(text.ToString()).Replace("http:", "https:")); }
/// <summary> /// 设置当前标签页的MvcHtmlString内容 /// </summary> /// <param name="content">MvcHtmlString内容</param> public TabItem SetContent(MvcHtmlString content) { this.HTMLContent = content.ToString(); return this; }
/// <summary> /// Adds the specified self. /// </summary> /// <param name="self">The self.</param> /// <param name="other">The other.</param> /// <param name="addSpace">if set to <c>true</c> [add space].</param> /// <returns></returns> public static MvcHtmlString Add(this MvcHtmlString self, string other, bool addSpace = false) { return(MvcHtmlString.Create(self.ToString() + (addSpace ? " " : "") + other)); }
public static MvcHtmlString TD(this HtmlHelper Html, MvcHtmlString content, string Class, params string[] htmlAttributes) { return Html.TD(content.ToString(), Class, htmlAttributes); }