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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:12:20+00:00 2026-05-23T06:12:20+00:00

I am using a ASP.NET MVC 3 Mvccontrib grid like so: @Html.Grid(Model).Columns(column => {

  • 0

I am using a ASP.NET MVC 3 Mvccontrib grid like so:

@Html.Grid(Model).Columns(column =>
{
  column.For(x => x.UserId).Named("ID");
  column.For(x => x.Name);
  column.Custom(@<div><img src='@item.ImageUrl' alt="@item.Name"/><a href="@item.Link">@item.Name</a></div>).Named("Name");
  column.For(x => x.Score).Named("Score");
})

But now I need to move this into a custom grid model:

@Html.MvcContrib().Grid(Model).WithModel(new MyGridModel()).Sort(ViewData["sort"] as GridSortOptions).Attributes(id => "grid", style => "width: 100%;")

with corresponding grid model:

public class MyGridModel : GridModel<MyModel>
{
  public MyGridModel()
  {
    Column.For(x => x.UserId);
    Column.For(x => x.Name);
    Column.For(x => x.ImageUrl);
    RenderUsing(new HtmlTableGridRenderer<MyModel>());
  }
}

But how can I do my custom column in my grid model?
Column.Custom(???);

  • 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-23T06:12:21+00:00Added an answer on May 23, 2026 at 6:12 am

    Try like this:

    public class MyGridModel : GridModel<MyModel>
    {
        public MyGridModel()
        {
            Column.For(x => x.UserId);
            Column.For(x => x.Name);
            Column.Custom(MyImage);
            Column.For(x => x.Score);
            RenderUsing(new HtmlTableGridRenderer<MyModel>());
        }
    
        private static IHtmlString MyImage(MyModel model)
        {
            var div = new TagBuilder("div");
            var img = new TagBuilder("img");
            var a = new TagBuilder("a");
            img.Attributes["src"] = model.ImageUrl;
            img.Attributes["alt"] = model.Name;
            a.Attributes["href"] = model.Link;
            a.SetInnerText(model.Name);
    
            div.InnerHtml = string.Format(
                "{0}{1}",
                img.ToString(TagRenderMode.SelfClosing),
                a.ToString()
            );
    
            return MvcHtmlString.Create(div.ToString());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,
I am using mvccontrib grid in asp.net mvc(C#) application. How can i apply css
I am using ASP.NET-MVC, and would like to format my html prior to sending
I'm using ASP.NET MVC Preview 4 and would like to know how to use
If you are using ASP.NET MVC how are you doing grid display? Rolled your
I'm using ASP.NET MVC with XmlResult from MVCContrib. I have an array of Xxxx
Using ASP.NET MVC's default view engine, you can declare a server-side comment like this:
Im using asp.net mvc 2. I have a model Supermodel that consists of 2
I am using ASP.NET MVC to develop a web application and would like to
using ASP.NET MVC, I have a Model, to which I'm attaching attributes so that

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.