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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:16:54+00:00 2026-06-08T20:16:54+00:00

I am using MVC3 WebGrid control to render a list of entities. Assume I

  • 0

I am using MVC3 WebGrid control to render a list of entities. Assume I have an Index like page that renders a list of users, or items, orders etc. All these entties are having a column called ID.

The WebGrid looks well, the only thing I want is that once the list is rendered I want to add the 3 action links Edit, Delete, Detail prior to all other columns.

Adding the following code works but I don’t want to repeat this code in all the pages:

@grid.GetHtml(columns: grid.Columns(
                grid.Column(header: "",
                   style: "text-align-center",
                       format: (item) => new
                        HtmlString(Html.ActionLink("Edit", "Edit", new { ID = item.ID     }).ToString() + " | " +
                                    Html.ActionLink("Details", "Details", new { ID = item.ID }).ToString() + " | " +
                                    Html.ActionLink("Delete", "Delete", new { ID = item.ID }).ToString()
                                   )
            ),
            grid.Column("FirstName"),
            grid.Column("LastName"),
            grid.Column("EmailAddress")
        )

Basically what I want is to say @Grid.Render(Model) … and it should create the first 3 action links and they render all the columns of the model.

I know that there are JQuery grids and MVCContrib etc but they are not the option please.

Any comments and tips will be appreciated.

  • 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-08T20:16:56+00:00Added an answer on June 8, 2026 at 8:16 pm

    You could write a custom extension method for the grid:

    using System.Linq;
    using System.Web;
    using System.Web.Helpers;
    using System.Web.Mvc;
    using System.Web.Mvc.Html;
    
    public static class WebGridExtensions
    {
        public static IHtmlString MyGetHtml(this WebGrid grid, HtmlHelper html)
        {
            var columns =
                (from n in grid.ColumnNames
                 select new WebGridColumn { ColumnName = n, CanSort = true }
                 ).ToList<WebGridColumn>();
            columns.Insert(0, grid.Links(html));
            return grid.GetHtml(columns: columns, exclusions: new[] { "ID" });
        }
    
        public static WebGridColumn Links(this WebGrid grid, HtmlHelper html)
        {
            return grid.Column(
                header: "",
                style: "text-align-center",
                format: item => new HtmlString(
                    html.ActionLink("Edit", "Edit", new { ID = item.ID }).ToString() + " | " +
                    html.ActionLink("Details", "Details", new { ID = item.ID }).ToString() + " | " +
                    html.ActionLink("Delete", "Delete", new { ID = item.ID }).ToString()
                )
            );
        }
    }
    

    and then use it:

    @model IEnumerable<MyViewModel>
    @{
        var grid = new WebGrid(Model);
    }
    @grid.MyGetHtml(Html)
    

    or if you want to control the building of the other columns:

    @grid.GetHtml(
        columns: grid.Columns(
            grid.Links(Html),
            grid.Column("FirstName"),
            grid.Column("LastName"),
            grid.Column("EmailAddress")
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MVC3 I have found that setting a SelectList's selected value correctly renders the
I'm using MVC3 and I have a model like this: public class Foo {
I am using MVC3, in which I have a page let say Home.cshtml with
I Have a little problem with WebGrid control for Asp.Net MVC3. What I want
I am using MVC3 and displaying my data in a webgrid. I would like
I'm using MVC3 and webgrid on a system. I like to know if it's
I'm using MVC3 w/ Razor and I have a model that has quite a
I'm using MVC3 - i have a javascript function that uses jQuery get() to
Using MVC3.NET I have a file upload method in a controller that works fine
I'm using MVC3 and in my view I have the following code block; Response.Redirect(@Url.Action(index,home,

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.