This is a continuation of this question Model class and Mapping
I had my Client class now working fine and it\'s defined as
using System;
using System.
After some trials and error I found that the TextBox EditorFor view was the culprit. I documented what I found in my answer here http://forums.asp.net/t/1855963.aspx/1?Validation+messages+don+t+show+up+what+is+missing+
Basically, as long as I use this EditorFor
@*@using WebDemo.Helper*@
@model CardNumbers.Objects.PhoneInfo
@* @Html.EditorFor(model => model.Phone, EditorTemplate.TextBox)*@
@Html.LabelFor(model => model.Phone)
@Html.EditorFor(model => model.Phone)
@Html.ValidationMessageFor(model => model.Phone)
@*@Html.EditorFor(model => model.Ext, EditorTemplate.TextBox)*@
@Html.LabelFor(model => model.Ext)
@Html.EditorFor(model => model.Ext)
@Html.ValidationMessageFor(model => model.Ext)
All seems to work OK. But if I try to switch to a shorter syntax and use this EditorFor for the textbox:
@Html.Label((ViewData.ModelMetadata.DisplayName??ViewData.ModelMetadata.PropertyName),
new Dictionary
{
{ "for", ViewData.ModelMetadata.PropertyName }
})
@Html.TextBox("", (object)Model,
new Dictionary
{
{ "id", ViewData.ModelMetadata.PropertyName },
{ "name", ViewData.ModelMetadata.PropertyName },
{ "class", "text-box single-line"},
{ "data-bind", "value: " + ViewData.ModelMetadata.PropertyName },
})
@Html.ValidationMessage(ViewData.ModelMetadata.PropertyName,
new Dictionary
{
{ "data-valmsg-for", ViewData.ModelMetadata.PropertyName }
})
Validation messages do not show anymore.
Hopefully this answer will help someone or you may see what I am missing here.