Condividi tramite


Get the Most out of WebGrid in ASP.NET MVC

My first MSDN Magazine article is up: Get the Most out of WebGrid in ASP.NET MVC. So, if you want to find out how to make the WebGrid component from WebMatrix fit in with ASP.NET MVC then take a peek…. https://msdn.microsoft.com/en-us/magazine/hh288075.aspx.

Thanks to Carl Nolan and Simon Ince for reviewing the article :-)

**UPDATE - the helpers are now up on NuGet: https://blogs.msdn.com/b/stuartleeks/archive/2012/01/24/webgrid-extensions-on-nuget.aspx **

Comments

  • Anonymous
    July 04, 2011
    I read your article, it was well written and very informative.

  • Anonymous
    July 04, 2011
    Good job!  Congratulations on your first publication.  Many more to follow I hope.

  • Anonymous
    July 18, 2011
    Good article, but what is the SafeCast method that you are using? I am guessing some extension method, but I haven't found any such method in the framework, and a Google search provides numerous hits, none of which appear to be an exact match.

  • Anonymous
    July 18, 2011
    Hi Graeme, the SafeCast was a little extension method that slightly simplified the code listing by removing a null check. It's in the code download under InfrastructureEnumerableExt public static class EnumerableExtensions    {        public static IEnumerable<TTarget> SafeCast<TTarget>(this IEnumerable source)        {            return source == null ? null : source.Cast<TTarget>();        }    }

  • Stuart
  • Anonymous
    July 18, 2011
    Thanks Stuart. Somehow I managed to completely miss the fact that there was a download.

  • Anonymous
    July 28, 2011
    Nice Article. Can you please explain how to edit WebGrid Column values. i.e i want user insert some values in our Gridview and on basis of values i have to display some calculation in gridview.

  • Anonymous
    August 15, 2011
    @Bhargav, to enable adding data you would need to render a set of input elements. You could then either add the data to the table in javascript (including performing the calculations), or you could send the data up to the server and retrieve the update to the grid (with calculations performed on the server)

  • Stuart
  • Anonymous
    May 01, 2012
    Great article Stuart. Is there a way to use WebGrid (or any other equivalent control is ASP.Net MVC) to select multiple rows ? Thanks Siva

  • Anonymous
    May 01, 2012
    @Siva, you could render the grid inside a <form> and render a custom column in the grid that is a checkbox. Submitting the form would then include any checkboxes that were selected. This wouldn't work across pages in the grid, but aside from that should be a relatively simple solution

  • Stuart
  • Anonymous
    August 27, 2012
    Stuart - this looks awesome! Question : do you know if it is compatible with MVC 4?

  • Anonymous
    August 27, 2012
    Kevin, I've not fully tested it by any means, but it worked in the ASP.NET MVC 4 project that I included it in a few days ago

  • Stuart
  • Anonymous
    October 17, 2012
    Hey Stuart, Nice Article. I was wodering if i could limit the user to check upto 3 checkboxes across different pages. I somehow got it working but it works for each page and not across. (when i move to 2nd page all the 1st page selections are erased). Please briefly let me know how could i deal with this. Thanks! Preethi

  • Anonymous
    October 17, 2012
    Another quick question of mine is could we reverse sort?( in the code and not on the address bar) I am doing a default sort on totalVotes column and it shows up in ascending order but i wanted the descending order, can i choose the order?? Thanks Preeti.

  • Anonymous
    January 19, 2014
    It is a nice article. Can a scroll bar be added to the grid? Thanks, Girish V

  • Anonymous
    January 19, 2014
    @Girish. Have you tried setting the height of the grid element (or one of its container elements)?