Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

.NETASP.NETMVC Grid
Home›.NET›Using MVC Grid In MVC

Using MVC Grid In MVC

By SibeeshVenu
December 11, 2015
3043
0
Share:
Select NuGet Package

In this post we will see how we can develop a MVC grid in our MVC application. There are so many grids are available in the industries, most of them are useful. Here we are going to use a grid called MVC grid, which uses bootstrap and jQuery. We will create some dynamic data using list first, once it is done, we will send this data to the MVC grid. Sounds good? I hope you will like this article.

Download Source Code

  • Using MVC Grid In MVC
  • Background

    I have been working with the Grid controls for a long long time. So far I have worked with jQX Grid, jQ Grid, jQuery Datatables, Pivot tables, KO grid etc. It is always interesting to work with some controls. I always loved it. recently I worked with MVC grid. So I thought of sharing that experience with you all.

    Create a MVC application

    First, we will start with creating an MVC application. Open your visual studio, then click File->New->Project. Name your project.

    Install MVC Grid

    The next step we are going to do is, installing the MVC grid to our project. To install, please right click your solution and click on Manage NuGet packages.

    Select NuGet Package

    Select NuGet Package

    Now you can see a new window, please search for MVC grid in the search box. And then click Install.

    Install_MVC_Grid_To_Project

    Install_MVC_Grid_To_Project

    Once you installed, you can see there is a new reference file has been added(GridMVC), you can also notice that two views are created (_Grig.cshtml,_GridPager.cshtml) and one CSS file and some scripts. Now we will move to our next step.

    Dependencies

    As I said before, MVC grid uses bootstrap for design. So the next thing we need to is to install bootstrap in our project. For that, go to NuGet packages again and search for bootstrap.

    Install_Bootstrap_To_Project

    Install_Bootstrap_To_Project

    You can see some new CSS files and scripts has been added to our project. So the set up has been done. Now what we need to do is to move on the coding part.

    Create a controller

    Now we can create a new controller, in my case I created a controller ‘HomeController’. In my controller I am going to call a model action which will return some dynamic data. See the code below.

    [csharp]
    public class HomeController : Controller
    {
    //
    // GET: /Home/

    public ActionResult Index()
    {
    Test t = new Test();
    var myList= t.GetData();
    return View(myList);
    }

    }
    [/csharp]

    As you can see I am creating an instance of my model Test, now we will create our model class. Shall we?

    Create Model

    I have create a model class with the name Test. Here I am creating some data dynamically using a for loop and assign those values to a list. Please see the codes below.

    [csharp]
    namespace AsyncActions.Models
    {
    public class Test
    {
    public List<Customer> GetData()
    {
    try
    {
    List<Customer> cst = new List<Customer>();
    for (int i = 0; i < 100; i++)
    {
    Customer c = new Customer();
    c.CustomerID = i;
    c.CustomerCode = "CST" + i;
    cst.Add(c);
    }
    return cst;
    }
    catch (Exception)
    {
    throw new NotImplementedException();
    }

    }
    }
    public class Customer
    {
    public int CustomerID { get; set; }
    public string CustomerCode { get; set; }
    }
    }
    [/csharp]

    As you can see I am creating a list of type Customer. Is that fine? Now what is pending? Yes, a view.

    Create a strongly typed view

    Now we are going to create a strongly typed view.

    Create_Strongly_Typed_View

    Create_Strongly_Typed_View

    When you create a view as strongly typed view, your view header will be as follows. @model List

    So our view is ready, now we can do some codes in our view to populate our grid. Are you ready? First thing is you need to include the needed references to our view, you can do this in the file called Layout.cshtml. Here I am going to add those references directly to the view.

    [html]
    <link href="~/Content/bootstrap-theme.css" rel="stylesheet" />
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-2.1.3.min.js"></script>
    <link href="~/Content/Gridmvc.css" rel="stylesheet" />
    <script src="~/Scripts/gridmvc.min.js"></script>
    [/html]

    Add the grid namespace

    You can add the grid namespace as follows.

    [html]
    @using GridMvc.Html
    [/html]

    Next thing is to add grid implementation.

    MVC Grid Implementation

    To add a MVC grid as our requirement, you need to add the codes as below.

    [csharp]
    @Html.Grid(Model).Columns(columns =>
    {
    columns.Add(foo => foo.CustomerID).Titled("Customer ID").SetWidth(50).Sortable(true).Filterable(true);
    columns.Add(foo => foo.CustomerCode).Titled("Customer Code").SetWidth(50).Sortable(true).Filterable(true);
    }).WithPaging(20)

    [/csharp]

    As you can see we are using the columns Customer.CustomerID and Customer.CustomerCode.

    Output

    MVC_Grid_With_Dynamic_Data

    MVC_Grid_With_Dynamic_Data

    Add more Grid features

    To set the paging we can use the option WithPaging(20).
    To add title we can use Titled property.
    To set width we can use SetWidth property.
    To set sort we can use Sortable property.
    To set filter we can use Filterable property.

    You can always see the additional options here .

    Conclusion

    Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

    Your turn. What do you think?

    A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

    Kindest Regards
    Sibeesh Venu

    TagsCSharpMVCMVC GridProducts
    Previous Article

    Use WordPress Without Wamp Server

    Next Article

    Create Custom Signature In Outlook

    0
    Shares
    • 0
    • +
    • 0
    • 0
    • 0

    SibeeshVenu

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

    Related articles More from author

    • Insertion_In_Table
      .NETAngularSQLWeb API

      TagIt Control With Data From Database Using Angular JS In MVC Web API

      February 25, 2016
      By SibeeshVenu
    • Change Themes Dynamically In Grid
      JQWidgetsJQX GridProducts

      Change Themes Dynamically In Grid

      October 28, 2015
      By SibeeshVenu
    • .NETASP.NETC#ProductsSpire.XLSVB.Net

      Working With Charts Using Spire.XLS

      August 11, 2015
      By SibeeshVenu
    • Advanced JQX Grid With All Functionality
      JQueryJQWidgetsJQX GridProducts

      Advanced JQX Grid With All Functionality

      October 29, 2014
      By SibeeshVenu
    • Chart Widgets With Server Side Data In MVC Using Angular JS And Web API Output
      .NETAngularASP.NETWeb API

      Chart Widgets With Server Side Data In MVC Using Angular JS And Web API

      March 17, 2016
      By SibeeshVenu
    • Using_Spire_PDF_Create_New_Project
      .NETASP.NETC#ProductsSpire.PDF

      Using Spire.PDF In Asp.Net

      August 24, 2015
      By SibeeshVenu
    0

    My book

    Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

    YouTube

    MICROSOFT MVP (2016-2022)

    profile for Sibeesh Venu - Microsoft MVP

    Recent Posts

    • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
    • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
    • Easily move data from one COSMOS DB to another
    • .NET 8 New and Efficient Way to Check IP is in Given IP Range
    • Async Client IP safelist for Dot NET
    • Post Messages to Microsoft Teams Using Python
    • Get Azure Blob Storage Blob Metadata Using PowerShell
    • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
    • Integrate Azure App Insights in 1 Minute to .Net6 Application
    • Azure DevOps Service Connection with Multiple Azure Resource Group

    Tags

    Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
    • .NET
    • Achievements
    • ADO.NET
    • Android
    • Angular
    • Arduino
    • Article Of The Day
    • ASP.NET
    • Asp.Net Core
    • Automobile
    • Awards
    • Azure
    • Azure CDN
    • azure devops
    • Blockchain
    • Blog
    • Browser
    • C-Sharp Corner
    • C#
    • Career Advice
    • Code Snippets
    • CodeProject
    • Cognitive Services
    • Cosmos DB
    • CSS
    • CSS3
    • Data Factory
    • Database
    • Docker
    • Drawings
    • Drill Down Chart
    • English
    • Excel Programming
    • Exporting
    • Facebook
    • Fun
    • Gadgets
    • GitHub
    • GoPro
    • High Map
    • HighChart
    • How to
    • HTML
    • HTML5
    • Ignite UI
    • IIS
    • Interview
    • IoT
    • JavaScript
    • JQuery
    • jQuery UI
    • JQWidgets
    • JQX Grid
    • Json
    • Knockout JS
    • Linux
    • Machine Learning
    • Malayalam
    • Malayalam Poems
    • MDX Query
    • Microsoft
    • Microsoft ADOMD
    • Microsoft MVP
    • Microsoft Office
    • Microsoft Technologies
    • Microsoft Windows
    • Microsoft Windows Server
    • Mobile
    • MongoDB
    • Monthly Winners
    • MVC
    • MVC Grid
    • MySQL
    • News
    • Node JS
    • npm
    • Number Conversions
    • October 2015
    • Office 365
    • Office Development
    • One Plus
    • Outlook
    • Page
    • PHP
    • Poems
    • PowerShell
    • Products
    • Q&A
    • Raspberry PI
    • React
    • SEO
    • SharePoint
    • Skype
    • Social Media
    • Software
    • Spire.Doc
    • Spire.PDF
    • Spire.XLS
    • SQL
    • SQL Server
    • SSAS
    • SSMS
    • Storage In HTML5
    • Stories
    • Third Party Software Apps
    • Tips
    • Tools
    • Translator Text
    • Uncategorized
    • Unit Testing
    • UWP
    • VB.Net
    • Videos
    • Virtual Machine
    • Visual Studio
    • Visual Studio 2017
    • Wamp Server
    • Web API
    • Web Platform Installer
    • Webinars
    • WebMatrix
    • Windows 10
    • Windows 7
    • Windows 8.1
    • Wordpress
    • Writing

    ABOUT ME

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

    Contact Me

    • info@sibeeshpassion.com

    Pages

    • About
    • Search
    • Privacy Policy
    • About
    • Search
    • Privacy Policy
    © Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
    Go to mobile version