Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8778641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:35:02+00:00 2026-06-13T19:35:02+00:00

This is a continuation of this question Model class and Mapping I had my

  • 0

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.ComponentModel.DataAnnotations;
using System.ComponentModel;

using DataAnnotationsExtensions;
using System.ComponentModel.DataAnnotations.Schema;
using System.Collections.Generic;

namespace CardNumbers.Objects
{
    [ComplexType]
    public class PhoneInfo
    {
        [DataType(DataType.PhoneNumber)]
        [StringLength(10)]
        [DisplayName("Phone")]
        public virtual string Phone { get; set; }

        [StringLength(5)]
        [DisplayName("Ext")]
        public virtual string Ext { get; set; }

        public bool HasValue
        {
            get
            {
                return (Phone != null || Ext != null);
            }
        }

    }

      [ComplexType]
      public class ContactDetail
      {
          //Constructor
          public ContactDetail()
          {
              phoneInfo = new PhoneInfo();
          }

          [StringLength(100)]
          [DisplayName("Contact Name")]
          [DisplayFormat(NullDisplayText = "")]
          public virtual string Contact { get; set; }

          [Email]
          [StringLength(100)]
          [DisplayName("Email")]
          public virtual string Email { get; set; }

          public virtual PhoneInfo phoneInfo { get; set; }
          public bool HasValue
          {
              get
              {
                  return (Contact != null || Email != null || phoneInfo.HasValue);
              }
          }
      }

/// <summary>
/// Client class (Client No, Client Name, Address, Contact1, Contact2 info, Created By, Modified By (operator and date)
/// </summary>
    public class Client
    {
        public Client()
        {
            Contact1 = new ContactDetail();
            Contact2 = new ContactDetail();
     }

        [Key]
        [Column("ClientId",TypeName = "int")]
        public virtual int Id { get; set; }
        [Required]
        [DisplayName("Client No")]
        [Column("client_no", TypeName = "smallint")]
        public virtual Int16 Number { get; set; }

        [Required]
        [Column("client_name", TypeName = "varchar")]
        [DisplayName("Client Name")]
        [MaxLength(30, ErrorMessage = "Client Name should not be longer than 30 characters" )]
        [MinLength(3, ErrorMessage = "Client Name is too short")]
        public virtual string Name { get; set; }

        [DataType(DataType.MultilineText)]
        public virtual string Address { get; set; }

        public virtual ContactDetail Contact1 {get; set;}
        public virtual ContactDetail Contact2 {get; set;}

        [ForeignKey("EnteredByOperator")]
        public string EnteredBy { get; set; }

        [InverseProperty("ClientsEnteredBy")]
        public virtual Operator EnteredByOperator { get; set; }

        [ForeignKey("ModifiedByOperator")]
        public string ModifiedBy { get; set; }

        [InverseProperty("ClientsUpdatedBy")]
        public virtual Operator ModifiedByOperator { get; set; }

        [DataType(DataType.DateTime)]
        [DisplayName("Created on")]
        public DateTime EnteredOn { get; set; }

        [DataType(DataType.DateTime)]
        [DisplayName("Modified on")]
        public DateTime? ModifiedOn { get; set; }

        public virtual ICollection<ClientOrder> ClientOrders { get; set; }

        public virtual ICollection<Reorder> Reorders { get; set; }
    }
}

I mapped column names using Fluent API and I also re-defined my original “repository” classes to be very similar to defined in this tutorial http://code.msdn.microsoft.com/ASPNET-MVC-Application-b01a9fe8

This is my current partial view for the client form called _ClientForm:

@using WebDemo.Helper
@model CardNumbers.Objects.Client
<fieldset>
    <legend>Client Info</legend>

    @Html.ValidationSummary(true)

    <input type="hidden" id="fntype" name="fntype">
    @Html.HiddenFor(model => model.Id)
    @Html.EditorFor(model => model.Number, EditorTemplate.TextBox)

    @Html.EditorFor(model => model.Name, EditorTemplate.TextBox)

    @Html.EditorFor(model => model.Address, EditorTemplate.EditBox)

    <div id="ContactsInfo">
        @*Contact 1*@

        <div id="Contact1">

         @*@Html.EditorFor(model=>model.Contact1)*@
            @Html.EditorFor(model=>model.Contact1.Contact, EditorTemplate.TextBox)
            @Html.EditorFor(model=>model.Contact1.Email, EditorTemplate.TextBox)
        </div>

        @*Contact2*@
        <div id="Contact2">

        @*   @Html.EditorFor(model => model.Contact2)*@
        </div>
    </div>
    @*<div class="clear"></div>*@
    <div id="SaveCancel" class="float-right">
        <button type="Submit" id="btnSave">Save</button>
        <button type="reset" id="btnCancel">Cancel</button>
    </div>
</fieldset>

I already tried to revert to original way of only one level and I also commented the second Contact2 info but still the e-mail validation doesn’t work and all other validations also don’t seem to work.

The EditorFor textboxes are defined based on this blog post http://fusionovation.com/post/2010/02/15/adding-a-rich-text-editor-to-asp-net-mvc-using-strongly-typed-helpers-dataannotations-amp-jquery.aspx

And these are two of the new EditorFor I added:
PhoneInfo.cshtml

@using WebDemo.Helper
@model CardNumbers.Objects.PhoneInfo

<div id="PhoneInfo">
    <div class="float-left">
        @Html.EditorFor(model => model.Phone, EditorTemplate.TextBox)
    </div>
    <div class="float-right">
        @Html.EditorFor(model => model.Ext, EditorTemplate.TextBox)
    </div>
</div>

And ContactDetail.cshtml

@using WebDemo.Helper
@model CardNumbers.Objects.ContactDetail

@Html.EditorFor(model => model.Contact, EditorTemplate.TextBox)
@Html.EditorFor(model => model.Email, EditorTemplate.TextBox)
@Html.EditorFor(model=>model.phoneInfo)

So, as you can see, the code of the views is now very compact.

However, with all of these in place the validations don’t see to fire anymore. I used to test validation on EMail by typing some garbage. It used to provide a validation message near the textbox. Now I observe that the email textbox takes the red border, but there is no message.

Do you see what I am missing now and if it’s possible to use complex type and validations?

To clarify, the _ClientForm is called from this Client view:

@model CardNumbers.Objects.Client

@{
    ViewBag.Title = "Client";
}

@section scripts {
    <script src="@Url.Content("~/Scripts/Clients.js")" type="text/javascript" ></script>
}

 <form id="frmClientsSearch">
        <label for="clientNo">Client No: </label>
        <input type="number" name="searchClientNo" class="numericOnly" /><br />
        <label for="clientName">Client Name: </label>
        <input type =  "text" size =25 value ="Please enter the search value" class="SelectOnEntry"
            name ="searchClientName" />

       <input type="button" id="btnClientsSearch" value ="Find / Refresh" />      
</form>
<div style="padding-left: 150px; padding-top: 50px; padding-bottom: 50px;" id="ClientsResults">
    <table id="flexClients" style="display: none">
    </table>
</div>
<div style="display: none">
   <form id="sform" title="Client Info">


        @{Html.RenderPartial("_ClientForm", Model)   ;}

    </form>
</div>

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:35:02+00:00Added an answer on June 13, 2026 at 7:35 pm

    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
    
    <div id="PhoneInfo">
        <div class="float-left">
            @* @Html.EditorFor(model => model.Phone, EditorTemplate.TextBox)*@
            <div class="editor-label">
                @Html.LabelFor(model => model.Phone)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Phone)
                @Html.ValidationMessageFor(model => model.Phone)
            </div>
        </div>
        <div class="float-right">
            @*@Html.EditorFor(model => model.Ext, EditorTemplate.TextBox)*@
            <div class="editor-label">
                @Html.LabelFor(model => model.Ext)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.Ext)
                @Html.ValidationMessageFor(model => model.Ext)
            </div>
        </div>
    </div>
    

    All seems to work OK. But if I try to switch to a shorter syntax and use this EditorFor for the textbox:

    <div class="editor-label">
        @Html.Label((ViewData.ModelMetadata.DisplayName??ViewData.ModelMetadata.PropertyName),
            new Dictionary<string, object>
                {
                    { "for", ViewData.ModelMetadata.PropertyName }
                })
    </div>
    <div class="editor-field">
        @Html.TextBox("", (object)Model,
            new Dictionary<string, object>
                {
                    { "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<string, object>
                {
                    { "data-valmsg-for", ViewData.ModelMetadata.PropertyName }
                })
    </div>
    

    Validation messages do not show anymore.

    Hopefully this answer will help someone or you may see what I am missing here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation question I had from a post yesterday: Initializing NSMutableDictionary (It's
This is a continuation of my question Python2.5.2 The code i developed is working
As a continuation of this question I am now looking for a way to
This is a continuation question from a previous question I have asked I now
This a continuation of this question. I have an Address class which contains basic
this is a continuation of question Catching an exception while using a Python 'with'
This is a continuation from a question that I had yesterday. I am trying
This question is a continuation of my previous question here zend models architecture (big
This is a continuation of this question from yesterday . Here are my three
This is a continuation of this question: Original Question (SO) The answer to this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.