I have an update controller action that checks validation.
if (!ModelState.IsValid) return View(InitialiseModel(model));
My view uses UIHelpers:
<%=Html.EditorForModel("MyModelTemplate") %>
I have a String property in my model called "Title" which has the attribute [Required]:
[Required]
[DisplayName("Resource title")]
public string Title { get; set; }
The UI template for this property looks like this:
<%= ViewData.ModelMetadata.IsRequired ? "*" : "" %>
<label for="<%=ViewData.ModelMetadata.PropertyName %>">
<%=ViewData.ModelMetadata.GetDisplayName() %>
</label>
<input type="text" id="<%=ViewData.ModelMetadata.PropertyName%>"
name="<%=ViewData.ModelMetadata.PropertyName%>" value="<%=Model%>" />
<%= Html.ValidationMessage(ViewData.ModelMetadata.PropertyName, "*") %>
The problem is ViewData.ModelMetadata.IsRequired is always false. And the validation message is never displayed. What am I missing?