Skip to content

Instantly share code, notes, and snippets.

View SteelHammerhands's full-sized avatar

SteelHammerhands

View GitHub Profile
@SteelHammerhands
SteelHammerhands / gist:6444221
Created September 4, 2013 23:32
Custom MVC Html extension. Wraps a LabelFor, EditorFor, and ValidationMessageFor for a property in a div. Saves a considerable amount of typing in Views. Also checks if the property has the Required attribute and adds a class to the label. Can pass in Html attributes which get applied to the containing div. This gives you hooks for styling and l…
namespace System.Web.Mvc
{
public static class MyEditorForExtensions
{
public static MvcHtmlString MyEditorFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
return MyEditorForInternal(htmlHelper, expression, HtmlHelper.AnonymousObjectToHtmlAttributes(null));
}
public static MvcHtmlString MyEditorFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes)