Here is the situation. I have some ViewModels that contain nested complex model types. Here is a fragment of one of the models (this is not a complete class):
public sealed class ContactDetailsViewModel : BaseViewModel
{
public ContactDetailsViewModel() : base() { }
public ContactDetailsViewModel(WebSession webSession) : base(webSession) { }
public ContactDetailsViewModel(WebSession webSession, string returnUrl) : base(webSession, returnUrl) { }
#region Contact
public ContactModel Contact { get; set; }
#endregion
And a fragment from the ContactModel class (not complete):
#region Company
[Required(AllowEmptyStrings = false)]
[StringLength(128)]
public string Company { get; set; }
#endregion
My problem is that I need to get validation attributes from the nested type of ContactModel model for client-side validation. I use the manual approach in most views because I do not use the * For () helper methods. That's what I'm doing:
@Html.TextBox(
_titleField,
Model.Contact.Title,
new Dictionary<string,object>(Html.GetUnobtrusiveValidationAttributes("Company"))
{
{ "class", "CTextBox" },
{ "style", "width:100%;" }
})
, , - , "". , "", , . , . , , , .
, , . , , "ModelMetadata", , . .
, , .
, , .