示例#1
0
 internal static MvcHtmlString DisplayNameForInternal <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, ModelMetadataProvider metadataProvider)
 {
     return(DisplayNameHelper(ModelMetadata.FromLambdaExpression(expression, html.ViewData),
                              ExpressionHelper.GetExpressionText(expression)));
 }
示例#2
0
 public static MvcHtmlString DisplayNameForSingleModelItem <TModel, TValue>(this HtmlHelper <IEnumerable <TModel> > html, Expression <Func <TModel, TValue> > expression)
 {
     return(DisplayNameForInternal(html, expression, metadataProvider: null));
 }
示例#3
0
 internal static MvcHtmlString DisplayNameInternal(this HtmlHelper html, string expression, ModelMetadataProvider metadataProvider)
 {
     return(DisplayNameHelper(ModelMetadata.FromStringExpression(expression, html.ViewData),
                              expression));
 }
示例#4
0
 //[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "This is an extension method")]
 internal static MvcHtmlString DisplayNameForInternal <TModel, TValue>(this HtmlHelper <IEnumerable <TModel> > html, Expression <Func <TModel, TValue> > expression, ModelMetadataProvider metadataProvider)
 {
     return(DisplayNameHelper(ModelMetadata.FromLambdaExpression(expression, new ViewDataDictionary <TModel>()),
                              ExpressionHelper.GetExpressionText(expression)));
 }
示例#5
0
 public static MvcHtmlString DisplayForModel(this HtmlHelper html, string templateName, object additionalViewData)
 {
     return(MvcHtmlString.Create(TemplateHelpers.TemplateHelper(html, html.ViewData.ModelMetadata, String.Empty, templateName, DataBoundControlMode.ReadOnly, additionalViewData)));
 }
示例#6
0
 public static MvcHtmlString DisplayForModel(this HtmlHelper html, string templateName, string htmlFieldName)
 {
     return(MvcHtmlString.Create(TemplateHelpers.TemplateHelper(html, html.ViewData.ModelMetadata, htmlFieldName, templateName, DataBoundControlMode.ReadOnly, null /* additionalViewData */)));
 }
示例#7
0
 public static MvcHtmlString DisplayFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, string templateName, string htmlFieldName, object additionalViewData)
 {
     return(TemplateHelpers.TemplateFor(html, expression, templateName, htmlFieldName, DataBoundControlMode.ReadOnly, additionalViewData));
 }
示例#8
0
 public static MvcHtmlString DisplayFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression)
 {
     return(TemplateHelpers.TemplateFor(html, expression, null /* templateName */, null /* htmlFieldName */, DataBoundControlMode.ReadOnly, null /* additionalViewData */));
 }
示例#9
0
 public static MvcHtmlString Display(this HtmlHelper html, string expression, string templateName, string htmlFieldName, object additionalViewData)
 {
     return(TemplateHelpers.Template(html, expression, templateName, htmlFieldName, DataBoundControlMode.ReadOnly, additionalViewData));
 }
示例#10
0
 public static MvcHtmlString Display(this HtmlHelper html, string expression, string templateName)
 {
     return(TemplateHelpers.Template(html, expression, templateName, null /* htmlFieldName */, DataBoundControlMode.ReadOnly, null /* additionalViewData */));
 }
        public static MvcHtmlString Link(this HtmlHelper self, string linkText, PotentialUrl location, object htmlAttributes = null)
        {
            var uri = PathHelpers.GenerateClientUrl(self.ViewContext.HttpContext, "~" + location.ToString());

            if (String.IsNullOrEmpty(linkText))
            {
                throw new ArgumentException("Link text not allowed to be null or empty", "linkText");
            }

            var tagBuilder = new TagBuilder("a")
            {
                InnerHtml = (!String.IsNullOrEmpty(linkText)) ? HttpUtility.HtmlEncode(linkText) : String.Empty
            };

            if (htmlAttributes != null)
            {
                var attributeDictionary = (htmlAttributes as IDictionary <string, object>) ?? HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
                tagBuilder.MergeAttributes(attributeDictionary);
            }

            tagBuilder.MergeAttribute("href", uri);
            var linkString = tagBuilder.ToString(TagRenderMode.Normal);

            return(MvcHtmlString.Create(linkString));
        }