43 lines
1.8 KiB
C#
43 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Mvc.Html;
|
|
using System.Web.Routing;
|
|
|
|
namespace EnVisage.Code.HtmlHelpers
|
|
{
|
|
public static class HtmlExtensions
|
|
{
|
|
public static MvcHtmlString ClientIdFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
|
|
{
|
|
return MvcHtmlString.Create(htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(ExpressionHelper.GetExpressionText(expression)));
|
|
}
|
|
public static MvcHtmlString NameFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
|
|
{
|
|
return MvcHtmlString.Create(htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)));
|
|
}
|
|
public static IHtmlString TextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression,
|
|
object htmlAttributes, bool disabled)
|
|
{
|
|
var attributes = new RouteValueDictionary(htmlAttributes);
|
|
if (disabled)
|
|
{
|
|
attributes["disabled"] = "disabled";
|
|
}
|
|
return htmlHelper.TextBoxFor(expression, attributes);
|
|
}
|
|
public static MvcHtmlString RadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression,
|
|
bool value, object htmlAttributes, bool disabled)
|
|
{
|
|
var attributes = new RouteValueDictionary(htmlAttributes);
|
|
if (disabled)
|
|
{
|
|
attributes["disabled"] = "disabled";
|
|
}
|
|
return htmlHelper.RadioButtonFor(expression, value, attributes);
|
|
}
|
|
}
|
|
} |