none
How to access column name RRS feed

  • Question

  • Hi everybody,

    If I am using Complex Types in my Code First Entity Model, the validation messages are not shown in the ASP.NET MVC application.

    I believe the reason is that my Id and name for the control don't match.

    I am wondering if there is any way programmatically access a Column Name I assign through the mapping?

    In other words, my current code is

     @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 },
                })

    in the EditorFor.

    My class uses Complex Type and this is how I assign values through mapping:

     this.Property(t => t.Contact1.Contact).IsUnicode(false).HasColumnName("Contact1");
                
                this.Property(t => t.Contact1.Email).IsUnicode(false).HasColumnName("C1_Email");
                this.Property(t => t.Contact1.phoneInfo.Phone).IsUnicode(false).HasColumnName("C1_Phone");
                this.Property(t => t.Contact1.phoneInfo.Ext).IsUnicode(false).HasColumnName("C1_Ext");
    
                this.Property(t => t.Contact2.Contact).IsUnicode(false).HasColumnName("Contact2");
                this.Property(t => t.Contact2.Email).IsUnicode(false).HasColumnName("C2_Email");
    
                this.Property(t => t.Contact2.phoneInfo.Phone).IsUnicode(false).HasColumnName("C2_Phone");
                this.Property(t => t.Contact2.phoneInfo.Ext).IsUnicode(false).HasColumnName("C2_Ext");
                
                this.Property(t => t.Address).IsUnicode(false);            

    In the resulting HTML I get by using EditorFor and this class I have Id = 'Email' and name = 'Contact1.Email' and the validation messages are not shown.

    Do you see the problem? What will be a solution for that?

    Thanks in advance.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    • Edited by Naomi N Sunday, November 4, 2012 7:34 PM
    Sunday, November 4, 2012 7:33 PM

All replies