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

  • Home
  • SEARCH
  • 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 6564411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:57:47+00:00 2026-05-25T13:57:47+00:00

I have, surprisingly, been searching on the internet how to bind a webgrid column

  • 0

I have, surprisingly, been searching on the internet how to bind a webgrid column from a complex type that is data source last 3 hours. But I could not find any useful information.
there is a topic on Complex WebGrid Binding in MVC 3, but it did not work in my scenario.

To simplify it, let’s say I have a list of Employee objects that I populate WebGrid from, each Employee have Address property which is Address type.

I would like to show the City property of Address field in the WebGrid along with other fields of Employee.

I assumed that grid.Column(“Address.City”) would work, but it does not. Is that something not supported, or I am doing something wrong.

Thanks for your help.

Regards

AnarchistGeek

  • 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-05-25T13:57:48+00:00Added an answer on May 25, 2026 at 1:57 pm

    This is the answer I got in ASP.NET forums and I wanted post it here in case others may need that.

    The thread link is http://forums.asp.net/p/1718114/4586676.aspx/1?Re%20Complex%20data%20type%20in%20WebGrid

    and the solution is(Tested):

    @functions{
        public class Employee
        {
            public string Name { get; set; }
            public Address Address { get; set; }
        }
        public class Address
        {
            public string City { get; set; }
        }
    }
    @{
        var myClasses = new List<Employee>{
              new Employee   { Name="A" , Address = new Address{ City="AA" }},
              new Employee   { Name="B" , Address = new Address{ City="BB" }},
              new Employee   { Name="C" , Address = new Address{ City="CC" }},
              new Employee   { Name="D" , Address = new Address{ City="DD" }},
    };
        var grid = new WebGrid(source: myClasses);
    }
    @grid.GetHtml(
    columns: grid.Columns(grid.Column("Address.City",header:"City"), grid.Column("Name")))
    

    I hope it helps others.

    Cheers.

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

Sidebar

Related Questions

Have some data in a sybase image type column that I want to use
I have been searching on this but it is surprisingly hard to come by
I have been having trouble find much documentation on o3d (not too surprisingly). Does
for that past couple of weeks I have been creating generic script that is
Surprisingly can't find a match for my question. I have one table that I
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
I have a strange problem which I have been trying to fix for some
I've been searching all over for an example of the XML needed to setup
Have been pulled down into the realm of CORBA... I am trying to quickly

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.