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 7013591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:24:30+00:00 2026-05-27T22:24:30+00:00

I am trying to format a WebGrid column so I can concatenate two pieces

  • 0

I am trying to format a WebGrid column so I can concatenate two pieces of data together (first and last name). Here is what I’m trying, but I will admit I don’t think I fully understand how to use the data (besides the basic scenarios) in WebGrid. (To the column name, the Teacher object is being passed to my view, but to actually get the teacher’s name, I have to get that information from the linked user object since users can play multiple roles.)

grid.Column(
    columnName: "Teacher.User",
    header: "Teacher",
    style: "",
    canSort: true,
    format: (item) =>
        {
            var text = Html.DisplayTextFor(item => item.LastName) + ", " + Html.DisplayTextFor(item => item.FirstName);
            return Html.Raw(text);
        }
)
  • 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-27T22:24:30+00:00Added an answer on May 27, 2026 at 10:24 pm

    Strongly typed helpers that take lambda expressions don’t work with dynamic expressions which is what the WebGrid helper is drowned with. The item argument that is passed to the format function is of type dynamic so you cannot use it with lambda expressions.

    I am trying to format a WebGrid column so I can concatenate two pieces
    of data together (first and last name

    What an excellent candidate for a view model. Just add another property in your User view model:

    public string FullName 
    { 
        get 
        {
            return string.Format("{0}, {1}", this.LastName, this.FirstName);
        }
    }
    

    that you will use in the view:

    grid.Column(
        columnName: "Teacher.User.FullName",
        header: "Teacher",
        style: "",
        canSort: true
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to place a DropDownList inside a WebGrid but I can't figure out
im trying to format this string into a fixed column style but cant get
I've been trying to change the format of a single column in a WebGrid
I'm trying to format a number using printf but can't find the correct mask.
I'm trying to format a column in a <table/> using a <col/> element. I
I am trying to format my code with textmate indent option . but textmate
After trying to format my JSON data by hand in javascript and failing miserably,
I am trying to format strings depending on the type ...but I feel it's
I am trying to format xml entries I have so that I can use
I am trying to format a {datetime?} property with stringFormat, but I don't know

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.