private string GenerateAnchor(PagerItem item) { if (_msAjaxPaging) { var routeValues = GetCurrentRouteValues(_ajax.ViewContext); if (item.PageIndex == 0) { routeValues[_pagerOptions.PageIndexParameterName] = ScriptPageIndexName; } else { routeValues[_pagerOptions.PageIndexParameterName] = item.PageIndex; } if (!string.IsNullOrEmpty(_routeName)) { return(_ajax.RouteLink(item.Text, _routeName, routeValues, _ajaxOptions).ToString()); } return(_ajax.RouteLink(item.Text, routeValues, _ajaxOptions).ToString()); } string url = GenerateUrl(item.PageIndex); if (_pagerOptions.UseJqueryAjax) { StringBuilder scriptBuilder = new StringBuilder(); //ignore OnSuccess property if (!string.IsNullOrEmpty(_ajaxOptions.OnFailure) || !string.IsNullOrEmpty(_ajaxOptions.OnBegin) || (!string.IsNullOrEmpty(_ajaxOptions.OnComplete) && _ajaxOptions.HttpMethod.ToUpper() != "GET")) { scriptBuilder.Append("$.ajax({type:\'").Append(_ajaxOptions.HttpMethod.ToUpper() == "GET" ? "get" : "post"); scriptBuilder.Append("\',url:$(this).attr(\'href\'),success:function(data,status,xhr){$(\'#"); scriptBuilder.Append(_ajaxOptions.UpdateTargetId).Append("\').html(data);}"); if (!string.IsNullOrEmpty(_ajaxOptions.OnFailure)) { scriptBuilder.Append(",error:").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnFailure)); } if (!string.IsNullOrEmpty(_ajaxOptions.OnBegin)) { scriptBuilder.Append(",beforeSend:").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnBegin)); } if (!string.IsNullOrEmpty(_ajaxOptions.OnComplete)) { scriptBuilder.Append(",complete:").Append( HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnComplete)); } scriptBuilder.Append("});return false;"); } else { if (_ajaxOptions.HttpMethod.ToUpper() == "GET") { scriptBuilder.Append("$(\'#").Append(_ajaxOptions.UpdateTargetId); scriptBuilder.Append("\').load($(this).attr(\'href\')"); if (!string.IsNullOrEmpty(_ajaxOptions.OnComplete)) { scriptBuilder.Append(",").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnComplete)); } scriptBuilder.Append(");return false;"); } else { scriptBuilder.Append("$.post($(this).attr(\'href\'), function(data) {$(\'#"); scriptBuilder.Append(_ajaxOptions.UpdateTargetId); scriptBuilder.Append("\').html(data);});return false;"); } } return(string.IsNullOrEmpty(url) ? _html.Encode(item.Text) : String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" onclick=\"{1}\">{2}</a>", url, scriptBuilder, item.Text)); } return("<a href=\"" + url + "\" onclick=\"window.open(this.attributes.getNamedItem('href').value,'_self')\"></a>"); }
public static MvcHtmlString BodyCssClass(this HtmlHelper html) { var pageAssetsBuilder = EngineContext.Current.Resolve <IPageAssetsBuilder>(); return(MvcHtmlString.Create(html.Encode(pageAssetsBuilder.GenerateBodyCssClasses()))); }
public static IDisposable BeginCollectionItem(this HtmlHelper html, string collectionName) { var idsToReuse = GetIdsToReuse(html.ViewContext.HttpContext, collectionName); string itemIndex = idsToReuse.Count > 0 ? idsToReuse.Dequeue() : Guid.NewGuid().ToString(); // autocomplete="off" is needed to work around a very annoying Chrome behaviour whereby it reuses old values after the user clicks "Back", which causes the xyz.index and xyz[...] values to get out of sync. html.ViewContext.Writer.WriteLine(string.Format("<input type=\"hidden\" name=\"{0}.index\" autocomplete=\"off\" value=\"{1}\" />", collectionName, html.Encode(itemIndex))); return(BeginHtmlFieldPrefixScope(html, string.Format("{0}[{1}]", collectionName, itemIndex))); }
private static string DatepickerTagBuilder <TModel, TProperty>(HtmlHelper <TModel> html, Expression <Func <TModel, TProperty> > expression, IDictionary <string, object> attributes) { var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); var div1 = new TagBuilder("div"); div1.AddCssClass("col-lg-" + attributes.Get <int>("controlcols", 4)); attributes.Remove("controlcols"); var wrap = new TagBuilder("div"); wrap.AddCssClass("input-group date"); var inline = attributes.Get <bool>("inline", false); attributes.Remove("inline"); if (inline) { wrap.Attributes.Add("style", "display: inline-table; width: 150px;"); } // id var name = ExpressionHelper.GetExpressionText(expression); string fullName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name); wrap.GenerateId(fullName + "_datepicker"); // data-date-format var dateFormat = attributes.ContainsKey("data-date-format") ? html.AttributeEncode(attributes["data-date-format"]) : "yyyy-mm-dd"; wrap.Attributes.Add("data-date-format", dateFormat); // data-date var dotNetDateFormat = dateFormat.Replace("m", "M"); var value = GetDateValue(metadata, dotNetDateFormat); wrap.Attributes.Add("data-date", attributes.ContainsKey("data-date") ? html.AttributeEncode(attributes["data-date"]) : value); var readOnly = attributes.ContainsKey("readonly"); // Date validation @ client-side is troublesome ~ var clientValidationEnabled = html.ViewContext.ClientValidationEnabled; var unobtrusiveJavaScriptEnabled = html.ViewContext.UnobtrusiveJavaScriptEnabled; html.ViewContext.ClientValidationEnabled = false; html.ViewContext.UnobtrusiveJavaScriptEnabled = false; // Why don't I hook attributes directly? wrap.InnerHtml += html.TextBox(fullName, value, new { @class = "form-control", @size = 16, @readonly = "readonly" }); html.ViewContext.ClientValidationEnabled = clientValidationEnabled; html.ViewContext.UnobtrusiveJavaScriptEnabled = unobtrusiveJavaScriptEnabled; if (!readOnly) { wrap.InnerHtml += "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-calendar\"></i></span>"; } if (attributes.ContainsKey("hints")) { wrap.InnerHtml += string.Format("<span class=\"help-block\">{0}</span>", html.Encode(attributes["hints"])); } div1.InnerHtml = wrap.ToString() + html.Hidden(fullName + ".DateFormat", dotNetDateFormat); return(inline ? div1.InnerHtml : div1.ToString()); }
/// <summary> /// Replaces new lines with BR tags but ensures that the rest of the content is encoded. /// </summary> /// <param name="helper"></param> /// <param name="value"></param> /// <returns></returns> public static HtmlString Multiline <T>(this HtmlHelper <T> helper, string value) { return(new HtmlString(helper.Encode(value).Replace(Environment.NewLine, "<br />"))); }
public string Encode(string value) => HtmlHelper.Encode(value);
public static MvcHtmlString DisplayMessage(this HtmlHelper html, string msg) => new MvcHtmlString("This is the message: <p>" + html.Encode(msg) + "</p>");
public static string AccountManagerFullName(this HtmlHelper html, Administrator accountManager) { return(accountManager == null ? string.Empty : html.Encode(accountManager.FullName)); }
public static MvcHtmlString EncodedReplace(this HtmlHelper htmlHelper, string input, string pattern, string replacement) { return(new MvcHtmlString(Regex.Replace(htmlHelper.Encode(input), pattern, replacement))); }
/// <summary> /// Generate all description parts /// </summary> /// <param name="html">HTML helper</param> /// <param name="part">Meta description part</param> /// <returns>Generated string</returns> public static MvcHtmlString NopMetaDescription(this HtmlHelper html, string part = "") { var pageHeadBuilder = EngineContext.Current.Resolve<IPageHeadBuilder>(); html.AppendMetaDescriptionParts(part); return MvcHtmlString.Create(html.Encode(pageHeadBuilder.GenerateMetaDescription())); }
/// <summary> /// Ruft die Validierungs-Attribute für unobtrusive JavaScript als Text ab. /// </summary> /// <returns></returns> public MvcHtmlString GetValidationAttributes() { IDictionary <string, object> unobtrusiveValidationAttributes = HtmlHelper.GetUnobtrusiveValidationAttributes(Name, ModelMetaData); MvcHtmlString attributesString = new MvcHtmlString(string.Join(" ", unobtrusiveValidationAttributes.Select(attr => string.Format("{0}=\"{1}\"", attr.Key, HtmlHelper.Encode(ReplacePropertyNameWithLabel(attr.Value, PropertyName, Label)))))); return(attributesString); }
/// <summary> /// Generate all title parts /// </summary> /// <param name="html">HTML helper</param> /// <param name="addDefaultTitle">A value indicating whether to insert a default title</param> /// <param name="part">Title part</param> /// <returns>Generated string</returns> public static MvcHtmlString NopTitle(this HtmlHelper html, bool addDefaultTitle, string part = "") { var pageHeadBuilder = EngineContext.Current.Resolve<IPageHeadBuilder>(); html.AppendTitleParts(part); return MvcHtmlString.Create(html.Encode(pageHeadBuilder.GenerateTitle(addDefaultTitle))); }
public static IDisposable BeginChildCollectionItem(this HtmlHelper html, string collectionName, string parentIdentifier, out string identifier) { var idsToReuse = GetIdsToReuse(html.ViewContext.HttpContext, collectionName, parentIdentifier); string itemIndex = idsToReuse.Count > 0 ? idsToReuse.Dequeue() : Guid.NewGuid().ToString(); html.ViewContext.Writer.WriteLine("<input type=\"hidden\" name=\"{0}.{1}.index\" autocomplete=\"off\" value=\"{2}\" />", parentIdentifier, collectionName, html.Encode(itemIndex)); // NOTE: We also prefix the identifier here with its parent identifier tag identifier = string.Format("{0}.{1}[{2}]", parentIdentifier, collectionName, itemIndex); return(BeginHtmlFieldPrefixScope(html, identifier)); }
private string GenerateAnchor(PagerItem item, int designOrPublish) { if (_msAjaxPaging) { var routeValues = GetCurrentRouteValues(_ajax.ViewContext); if (item.PageIndex == 0) { routeValues[_pagerOptions.PageIndexParameterName] = ScriptPageIndexName; } else { routeValues[_pagerOptions.PageIndexParameterName] = item.PageIndex; } if (!string.IsNullOrEmpty(_routeName)) { return(_ajax.RouteLink(item.Text, _routeName, routeValues, _ajaxOptions).ToString()); } return(_ajax.RouteLink(item.Text, routeValues, _ajaxOptions).ToString()); } /**region 使用当前页面-zhenhua.du 2012.2.9**/ string url = _pagerOptions.UseCurrentPageUrl ? GetCurrentPageUrl(item.PageIndex, designOrPublish) : GenerateUrl(item.PageIndex); if (_pagerOptions.UseJqueryAjax) { StringBuilder ehBuilder = new StringBuilder(); //ignore OnSuccess property if (!string.IsNullOrEmpty(_ajaxOptions.OnFailure) || !string.IsNullOrEmpty(_ajaxOptions.OnBegin)) { ehBuilder.Append("$.ajax({url:$(this).attr(\'href\'),success:function(data,status,xhr){$(\'#"); ehBuilder.Append(_ajaxOptions.UpdateTargetId).Append("\').html(data);}"); if (!string.IsNullOrEmpty(_ajaxOptions.OnFailure)) { ehBuilder.Append(",error:").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnFailure)); } if (!string.IsNullOrEmpty(_ajaxOptions.OnBegin)) { ehBuilder.Append(",beforeSend:").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnBegin)); } if (!string.IsNullOrEmpty(_ajaxOptions.OnComplete)) { ehBuilder.Append(",complete:").Append( HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnComplete)); } ehBuilder.Append("});return false;"); } else if (!string.IsNullOrEmpty(_ajaxOptions.OnSuccess) && string.IsNullOrEmpty(_ajaxOptions.OnComplete) && string.IsNullOrEmpty(_ajaxOptions.UpdateTargetId)) { /**使用自定义**/ string callback = _ajaxOptions.OnSuccess.Replace("%_PageIndex_%", item.PageIndex.ToString()); ehBuilder.AppendFormat("{0};return false;", callback); } else { ehBuilder.Append("$(\'#").Append(_ajaxOptions.UpdateTargetId); ehBuilder.Append("\').load($(this).attr(\'href\')"); if (!string.IsNullOrEmpty(_ajaxOptions.OnComplete)) { ehBuilder.Append(",").Append(HttpUtility.HtmlAttributeEncode(_ajaxOptions.OnComplete)); } ehBuilder.Append(");return false;"); } return(string.IsNullOrEmpty(url) ? _html.Encode(item.Text) : String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\" onclick=\"{1}\">{2}</a>", GenerateUrl(item.PageIndex), ehBuilder, item.Text)); } return("<a href=\"" + url + "\" onclick=\"window.open(this.attributes.getNamedItem('href').value,'_self')\"></a>"); }
internal static string StringTemplate(HtmlHelper html) { return html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue); }
/// <summary> /// Outputs a link to the team information page /// </summary> /// <param name="htmlHelper"></param> /// <param name="linkText">No need to encode</param> /// <param name="teamId"></param> /// <returns></returns> public static MvcHtmlString TeamLink(this HtmlHelper htmlHelper, string linkText, int teamId) { return(htmlHelper.ActionLink(htmlHelper.Encode(linkText), "View", "Teams", new { id = teamId }, new { title = "Click to view team information" })); }
public static string LabeledPropertyValue(this HtmlHelper htmlHelper, string label, string value) { return(string.Format("<label>{0}: </label><span>{1}</span>", label, htmlHelper.Encode(value))); }
public static MvcHtmlString FixtureLink(this HtmlHelper htmlHelper, string linkText, int fixtureId) { return(htmlHelper.ActionLink(htmlHelper.Encode(linkText), "ViewMatch", "Stats", new { id = fixtureId }, new { title = "Click to view fixture stats" })); }
public string Encode(object value) => HtmlHelper.Encode(value);
internal static MvcHtmlString DropDownbase <VM, TItem, TDisplay, TValue>( this HtmlHelper <VM> htmlHelper, string name, object value, List <ExtendedSelectListItem> items, IDictionary <string, object> htmlAttributes, bool allowsMultipleValues, bool useGroups, ModelMetadata metaData = null) { string partialName = name; if (name == null) { throw new ArgumentNullException("name"); } name = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name); if (items == null) { throw new ArgumentNullException("items"); } object defaultValue = (allowsMultipleValues) ? htmlHelper.GetModelStateValue(name, typeof(string[])) : htmlHelper.GetModelStateValue(name, typeof(string)); if (defaultValue == null) { defaultValue = value; } if (defaultValue != null) { IEnumerable defaultValues = (allowsMultipleValues) ? defaultValue as IEnumerable : new[] { defaultValue }; IEnumerable <string> values = (from object currValue in defaultValues select Convert.ToString(currValue, CultureInfo.CurrentCulture)).ToList(); HashSet <string> selectedValues = new HashSet <string>(values, StringComparer.OrdinalIgnoreCase); foreach (ExtendedSelectListItem item in items) { item.Selected = (item.Value != null) ? selectedValues.Contains(item.Value) : selectedValues.Contains(item.Text); } } StringBuilder listItemBuilder = new StringBuilder(); if (useGroups) { foreach (var group in items.GroupBy(i => i.GroupKey)) { var groupProps = group.Select(it => new { Name = it.GroupName, Attrs = it.GroupAttributes }).FirstOrDefault(); IDictionary <string, object> dictionary = groupProps.Attrs as IDictionary <string, object>; if (group.Key != null && groupProps.Name != null) { if (dictionary != null) { listItemBuilder.AppendLine(string.Format("<optgroup label=\"{0}\" value=\"{1}\" {2}>", htmlHelper.Encode(groupProps.Name), htmlHelper.Encode(group.Key), BasicHtmlHelper.GetAttributesString(dictionary))); } else { listItemBuilder.AppendLine(string.Format("<optgroup label=\"{0}\" value=\"{1}\" {2}>", htmlHelper.Encode(groupProps.Name), htmlHelper.Encode(group.Key), BasicHtmlHelper.GetAttributesString(groupProps.Attrs))); } } foreach (ExtendedSelectListItem item in group) { listItemBuilder.AppendLine(ListItemToOption(item)); } if (group.Key != null && groupProps.Name != null) { listItemBuilder.AppendLine("</optgroup>"); } } } else { foreach (ExtendedSelectListItem item in items) { listItemBuilder.AppendLine(ListItemToOption(item)); } } TagBuilder tagBuilder = new TagBuilder("select") { InnerHtml = listItemBuilder.ToString() }; tagBuilder.MergeAttributes(htmlAttributes); tagBuilder.MergeAttribute("name", name, true /* replaceExisting */); tagBuilder.GenerateId(name); if (allowsMultipleValues) { tagBuilder.MergeAttribute("multiple", "multiple"); } ModelState modelState; if (htmlHelper.ViewData.ModelState.TryGetValue(name, out modelState)) { if (modelState.Errors.Count > 0) { tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName); } } tagBuilder.MergeAttributes(MvcEnvironment.GetUnobtrusiveValidation(htmlHelper, partialName, metaData)); return(MvcHtmlString.Create(tagBuilder.ToString())); }
public static string TruncateForDisplay(this HtmlHelper helper, string text, int maxLength) { return(TextUtil.TruncateForDisplay(helper.Encode(text), maxLength)); }
public static MvcHtmlString CustomNgCheckBoxFor <TModel>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, bool> > expression, object lblHtmlAttributes = null, object checkHtmlAttributes = null, string Context = null)//, object txtHtmlAttributes = null { var lblRouteValueDictionary = new RouteValueDictionary(lblHtmlAttributes); var CheckBoxRouteValueDictionary = new RouteValueDictionary(checkHtmlAttributes); //var txtRouteValueDictionary = new RouteValueDictionary(txtHtmlAttributes); var Label = System.Web.Mvc.Html.LabelExtensions.LabelFor(htmlHelper, expression, lblRouteValueDictionary).ToHtmlString(); var expressionName = GetPropertyName(expression); var metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); var displayName = metadata.DisplayName; var controlGroupDiv = new TagBuilder("div"); controlGroupDiv.AddCssClass("checkbox"); var label = new TagBuilder("label"); var checkBox = new TagBuilder("input"); checkBox.Attributes.Add("type", "checkbox"); checkBox.MergeAttributes(CheckBoxRouteValueDictionary); checkBox.Attributes.Add("ng-model", "_Object." + expressionName); if (CheckBoxRouteValueDictionary.ContainsKey("ng_disabled")) { checkBox.Attributes.Add("ng-disabled", CheckBoxRouteValueDictionary["ng_disabled"].ToString()); } if (CheckBoxRouteValueDictionary.ContainsKey("ng_click")) { checkBox.Attributes.Add("ng-click", CheckBoxRouteValueDictionary["ng_click"].ToString()); } if (IsReadOnly(htmlHelper, expression, CheckBoxRouteValueDictionary)) { checkBox.Attributes.Add("disabled", "disabled"); } var validationspan = new TagBuilder("span"); var textBox = System.Web.Mvc.Html.InputExtensions.TextBoxFor(htmlHelper, expression, CheckBoxRouteValueDictionary); if (NotAuthorized(htmlHelper, expression, CheckBoxRouteValueDictionary)) { return(System.Web.Mvc.Html.InputExtensions.HiddenFor(htmlHelper, expression, CheckBoxRouteValueDictionary)); } //if (CheckBoxRouteValueDictionary.ContainsKey("emptyWrapper")) //{ // return MvcHtmlString.Create(textBox.ToHtmlString() + validationspan.ToString()); //} //else //{ // return WrapinFormGroup(textBox.ToHtmlString() + validationspan.ToString(), Label); //} label.InnerHtml = checkBox.ToString(TagRenderMode.SelfClosing); label.InnerHtml += htmlHelper.Encode(displayName); controlGroupDiv.InnerHtml = label.ToString(); return(MvcHtmlString.Create(controlGroupDiv.ToString())); }
public static string ScaffoldLink(this HtmlHelper html, string text, string tableName, string action, RouteValueDictionary routeValues) { var url = new UrlHelper(html.ViewContext.RequestContext); return String.Format("<a href=\"{0}\">{1}</a>", url.ScaffoldUrl(tableName, action, routeValues), html.Encode(text)); }
public static MvcHtmlString Excerpt(this HtmlHelper html, string markup, int length) { return(MvcHtmlString.Create(html.Encode(HttpUtility.HtmlDecode(markup.RemoveTags()).Ellipsize(length)))); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.PostContent.SetContent($"<footer>{HtmlHelper.Encode(ViewData["footer"])}</footer>"); }
public static MvcHtmlString TypeLink(this HtmlHelper helper, string fullname) { if (fullname.IndexOf(".", StringComparison.Ordinal) == -1) { fullname = "System." + fullname; } // Change this to checking if the namespace is in the Application.Namespaces if (fullname.StartsWith("System.") || fullname.StartsWith("Microsoft.")) { var query = fullname; // Replace types with a T if (fullname.IndexOf("<", StringComparison.Ordinal) != -1) { // This only matches one generic argument, however that still works with IDictionary<TKey,TValue> + google var regex = new Regex(@"(.*)\<([a-zA-Z0-9\.]*)\>"); query = regex.Replace(fullname, "$1<T>"); } return(MvcHtmlString.Create("<a href=\"http://www.google.com/search?q=" + query + "&btnI=Im+Feeling+Lucky\">" + helper.Encode(fullname) + "</a>")); } return(helper.ActionLink(fullname, "Type", new { id = fullname })); }
public static IDisposable BeginCollectionItem(this HtmlHelper html, string collectionName, string prefix) { // autocomplete="off" is needed to work around a very annoying Chrome behaviour whereby it reuses old values after the user clicks "Back", which causes the xyz.index and xyz[...] values to get out of sync. html.ViewContext.Writer.WriteLine(string.Format("<input type=\"hidden\" name=\"{0}.index\" autocomplete=\"off\" value=\"{1}\" />", collectionName, html.Encode(prefix))); return(BeginHtmlFieldPrefixScope(html, string.Format("{0}[{1}]", collectionName, prefix))); }
public static MvcHtmlString Meta(this HtmlHelper helper, string name, object value) { return(MvcHtmlString.Create(string.Format("<meta name=\"{0}\" content=\"{1}\" />", name.ToLower(), helper.Encode(value)))); }
public static IHtmlString Ellipsize(this HtmlHelper htmlHelper, string text, int characterCount, string ellipsis) { return(new HtmlString(htmlHelper.Encode(text).Ellipsize(characterCount, ellipsis))); }
public static IHtmlString ConditionalAttribute(this HtmlHelper html, bool condition, string attributeName, string value) { if (condition) { return(new MvcHtmlString(!string.IsNullOrEmpty(value) ? attributeName + "=\"" + html.Encode(value) + "\"" : attributeName)); } return(MvcHtmlString.Empty); }
internal static string ObjectTemplate(HtmlHelper html, TemplateHelpers.TemplateHelperDelegate templateHelper) { ViewDataDictionary viewData = html.ViewContext.ViewData; TemplateInfo templateInfo = viewData.TemplateInfo; ModelMetadata modelMetadata = viewData.ModelMetadata; StringBuilder builder = new StringBuilder(); if (templateInfo.TemplateDepth > 1) { if (modelMetadata.Model == null) { return modelMetadata.NullDisplayText; } // DDB #224751 string text = modelMetadata.SimpleDisplayText; if (modelMetadata.HtmlEncode) { text = html.Encode(text); } return text; } foreach (ModelMetadata propertyMetadata in modelMetadata.Properties.Where(pm => ShouldShow(pm, templateInfo))) { if (!propertyMetadata.HideSurroundingHtml) { string label = LabelExtensions.LabelHelper(html, propertyMetadata, propertyMetadata.PropertyName).ToHtmlString(); if (!String.IsNullOrEmpty(label)) { builder.AppendFormat(CultureInfo.InvariantCulture, "<div class=\"editor-label\">{0}</div>\r\n", label); } builder.Append("<div class=\"editor-field\">"); } builder.Append(templateHelper(html, propertyMetadata, propertyMetadata.PropertyName, null /* templateName */, DataBoundControlMode.Edit, null /* additionalViewData */)); if (!propertyMetadata.HideSurroundingHtml) { builder.Append(" "); builder.Append(html.ValidationMessage(propertyMetadata.PropertyName)); builder.Append("</div>\r\n"); } } return builder.ToString(); }
public static MvcHtmlString RenderTaxonNameWithStatus(this HtmlHelper htmlHelper, TaxonNameViewModel taxonName) { string name = taxonName.Name; string author = taxonName.Author; int sortOrder = taxonName.IsScientificName ? taxonName.TaxonCategorySortOrder : -1; bool isOriginal = taxonName.IsOriginal; var result = new StringBuilder(); ITaxonCategory genusTaxonCategory = CoreData.TaxonManager.GetTaxonCategory( CoreData.UserManager.GetCurrentUser(), TaxonCategoryId.Genus); if (sortOrder >= genusTaxonCategory.SortOrder) { var tag = new TagBuilder("em"); tag.SetInnerText(name); result.Append(tag.ToString()); } else { result.Append(htmlHelper.Encode(name)); } if (!string.IsNullOrEmpty(author)) { result.Append(" "); result.Append(htmlHelper.Encode(author)); } if (isOriginal) { result.Append("*"); } List <string> extraInfo = new List <string>(); // Spelling variant if (taxonName.NameUsageId == (int)TaxonNameUsageId.Accepted && taxonName.IsScientificName && !taxonName.IsRecommended) { extraInfo.Add(Resources.DyntaxaResource.TaxonNameSharedSpellingVariant); } // Heterotypic or Homotypic if (taxonName.NameUsageId == (int)TaxonNameUsageId.Heterotypic || taxonName.NameUsageId == (int)TaxonNameUsageId.Homotypic) { extraInfo.Add(taxonName.NameUsage); } // Name status isn't Correct. if (taxonName.NameStatusId != (int)TaxonNameStatusId.ApprovedNaming) { extraInfo.Add(taxonName.NameStatus); } else if (taxonName.CategoryTypeId == (int)TaxonNameCategoryTypeId.Identifier && !(taxonName.NameStatusId == (int)TaxonNameStatusId.ApprovedNaming || taxonName.NameStatusId == (int)TaxonNameStatusId.Informal)) { // Identifier status isn't correct. extraInfo.Add(taxonName.NameStatus); } if (extraInfo.IsNotEmpty()) { result.Append(" ["); result.Append(string.Join(", ", extraInfo)); result.Append("]"); } //// Add information inside [] if name status isn't Correct, //// or name usage is Heterotypic or homotypic. //if (taxonName.NameStatusId != (int)TaxonNameStatusId.ApprovedNaming || taxonName.NameUsageId == (int)TaxonNameUsageId.Heterotypic || taxonName.NameUsageId == (int)TaxonNameUsageId.Homotypic) //{ // bool itemHasBeenAdded = false; // result.Append(" ["); // if (taxonName.NameUsageId == (int)TaxonNameUsageId.Accepted && // taxonName.IsScientificName && !taxonName.IsRecommended) // { // result.Append(Resources.DyntaxaResource.TaxonNameSharedSpellingVariant); // itemHasBeenAdded = true; // } // if (taxonName.NameUsageId == (int)TaxonNameUsageId.Heterotypic || // taxonName.NameUsageId == (int)TaxonNameUsageId.Homotypic) // { // if (itemHasBeenAdded) // { // result.Append(", "); // } // result.Append(taxonName.NameUsage); // itemHasBeenAdded = true; // } // if (taxonName.NameStatusId != (int)TaxonNameStatusId.ApprovedNaming) // { // if (itemHasBeenAdded) // { // result.Append(", "); // } // result.Append(taxonName.NameStatus); // } // result.Append("]"); //} return(MvcHtmlString.Create(result.ToString())); }
internal static string UrlTemplate(HtmlHelper html) { return String.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\">{1}</a>", html.AttributeEncode(html.ViewContext.ViewData.Model), html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue)); }
internal static string UrlTemplate(HtmlHelper html, object attributes = null) { var dataAttributes = html.ViewContext.ViewData.ModelMetadata.AdditionalValues.GetDataAttributes(); var customAttributes = html.ViewContext.ViewData.ModelMetadata.AdditionalValues.GetCustomAttributes(); dataAttributes.MergeAttributes(customAttributes); TagBuilder mailTo = new TagBuilder("a"); mailTo.MergeAttribute("href", html.AttributeEncode(html.ViewContext.ViewData.Model)); mailTo.MergeAttributes(dataAttributes); mailTo.InnerHtml = html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue); return mailTo.ToString(TagRenderMode.Normal); }