Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Html.LabelFor(m => m.OrganisationId)
- [DisplayName("OrganisationId *")]
- [Required(ErrorMessage = "OrganisationIdis required")]
- public string OrganisationId { get; set; }
- @Html.LabelFor(m=>model.OrganisationId)
- [Required]
- [UIHint("RequiredTemplate")]//this does the trick which should match the file name.
- [Display(Name="Organization Id")]
- public string Name { get; set; }
- <font style="color:Red">*</font>@Html.LabelFor(m => m)
- <div class="display-field">
- @Html.DisplayFor(m => m.Name)
- </div>
- public static MvcHtmlString LabelForX<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string requiredText = "required", string innerText = "*" )
- {
- ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
- string htmlFieldName = ExpressionHelper.GetExpressionText(expression);
- string labelText = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
- if (String.IsNullOrEmpty(labelText))
- {
- return MvcHtmlString.Empty;
- }
- var tag = new TagBuilder("label");
- tag.Attributes.Add("for", html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName));
- tag.SetInnerText(labelText);
- if (metadata.IsRequired)
- {
- var span = new TagBuilder("abbr");
- span.Attributes.Add("title", requiredText);
- span.Attributes.Add("class", "labelRequired");
- span.SetInnerText(innerText);
- tag.Attributes.Add("class", "labelRequired");
- tag.InnerHtml = span.ToString(TagRenderMode.Normal) + " " + labelText;
- }
- return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
- }
- @Html.LabelForX(x => x.YourRequieredField)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement