<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MVC Grid &#8211; Sibeesh Passion</title>
	<atom:link href="https://mail.sibeeshpassion.com/tag/mvc-grid/feed/" rel="self" type="application/rss+xml" />
	<link>https://mail.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:15:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>MVC Grid &#8211; Sibeesh Passion</title>
	<link>https://mail.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Using MVC Grid In MVC</title>
		<link>https://mail.sibeeshpassion.com/using-mvc-grid-in-mvc/</link>
					<comments>https://mail.sibeeshpassion.com/using-mvc-grid-in-mvc/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 11 Dec 2015 00:00:15 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC Grid]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Products]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10981</guid>

					<description><![CDATA[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 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we will see how we can develop a MVC grid in our <a href="http://sibeeshpassion.com/category/mvc/" target="_blank" rel="noopener">MVC </a>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 <a href="http://sibeeshpassion.com/category/jQuery/" target="_blank" rel="noopener">jQuery</a>. 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. </p>
<p><strong>Download Source Code</strong></p>
<li><a href="https://code.msdn.microsoft.com/Using-MVC-Grid-In-MVC-4111f300" target="_blank" rel="noopener">Using MVC Grid In MVC</a></li>
<p><strong>Background</strong></p>
<p>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. </p>
<p><strong>Create a MVC application</strong></p>
<p>First, we will start with creating an MVC application. Open your visual studio, then click File->New->Project. Name your project. </p>
<p><strong>Install MVC Grid</strong></p>
<p>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. </p>
<div id="attachment_10982" style="width: 469px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Select_NuGet_Package.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-10982" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Select_NuGet_Package.png" alt="Select NuGet Package" width="459" height="673" class="size-full wp-image-10982" srcset="/wp-content/uploads/2015/11/Select_NuGet_Package.png 459w, /wp-content/uploads/2015/11/Select_NuGet_Package-205x300.png 205w, /wp-content/uploads/2015/11/Select_NuGet_Package-400x586.png 400w, /wp-content/uploads/2015/11/Select_NuGet_Package-409x600.png 409w" sizes="(max-width: 459px) 100vw, 459px" /></a><p id="caption-attachment-10982" class="wp-caption-text">Select NuGet Package</p></div>
<p>Now you can see a new window, please search for MVC grid in the search box. And then click Install. </p>
<div id="attachment_10983" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Install_MVC_Grid_To_Project-e1448285055873.png"><img decoding="async" aria-describedby="caption-attachment-10983" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Install_MVC_Grid_To_Project-e1448285055873.png" alt="Install_MVC_Grid_To_Project" width="650" height="433" class="size-full wp-image-10983" srcset="/wp-content/uploads/2015/11/Install_MVC_Grid_To_Project-e1448285055873.png 650w, /wp-content/uploads/2015/11/Install_MVC_Grid_To_Project-e1448285055873-300x200.png 300w, /wp-content/uploads/2015/11/Install_MVC_Grid_To_Project-e1448285055873-400x266.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10983" class="wp-caption-text">Install_MVC_Grid_To_Project</p></div>
<p>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.</p>
<p><strong>Dependencies </strong></p>
<p>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.</p>
<div id="attachment_10984" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Install_Bootstrap_To_Project-e1448285364634.png"><img decoding="async" aria-describedby="caption-attachment-10984" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Install_Bootstrap_To_Project-e1448285364634.png" alt="Install_Bootstrap_To_Project" width="650" height="433" class="size-full wp-image-10984" srcset="/wp-content/uploads/2015/11/Install_Bootstrap_To_Project-e1448285364634.png 650w, /wp-content/uploads/2015/11/Install_Bootstrap_To_Project-e1448285364634-300x200.png 300w, /wp-content/uploads/2015/11/Install_Bootstrap_To_Project-e1448285364634-400x266.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10984" class="wp-caption-text">Install_Bootstrap_To_Project</p></div>
<p>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. </p>
<p><strong>Create a controller </strong></p>
<p>Now we can create a new controller, in my case I created a controller &#8216;HomeController&#8217;. In my controller I am going to call a model action which will return some dynamic data. See the code below. </p>
<p>[csharp]<br />
public class HomeController : Controller<br />
    {<br />
        //<br />
        // GET: /Home/</p>
<p>        public ActionResult Index()<br />
        {<br />
            Test t = new Test();<br />
            var myList= t.GetData();<br />
            return View(myList);<br />
        }</p>
<p>    }<br />
[/csharp]</p>
<p>As you can see I am creating an instance of my model Test, now we will create our model class. Shall we?</p>
<p><strong>Create Model </strong></p>
<p>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. </p>
<p>[csharp]<br />
namespace AsyncActions.Models<br />
{<br />
    public class Test<br />
    {<br />
        public List&lt;Customer&gt; GetData()<br />
        {<br />
            try<br />
            {<br />
                List&lt;Customer&gt; cst = new List&lt;Customer&gt;();<br />
                for (int i = 0; i &lt; 100; i++)<br />
                {<br />
                    Customer c = new Customer();<br />
                    c.CustomerID = i;<br />
                    c.CustomerCode = &quot;CST&quot; + i;<br />
                    cst.Add(c);<br />
                }<br />
                return cst;<br />
            }<br />
            catch (Exception)<br />
            {<br />
                throw new NotImplementedException();<br />
            }</p>
<p>        }<br />
    }<br />
    public class Customer<br />
    {<br />
        public int CustomerID { get; set; }<br />
        public string CustomerCode { get; set; }<br />
    }<br />
}<br />
[/csharp]</p>
<p>As you can see I am creating a list of type Customer. Is that fine? Now what is pending? Yes, a view.</p>
<p><strong>Create a strongly typed view</strong></p>
<p>Now we are going to create a strongly typed view. </p>
<div id="attachment_10985" style="width: 519px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/Create_Strongly_Typed_View.png"><img decoding="async" aria-describedby="caption-attachment-10985" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/Create_Strongly_Typed_View.png" alt="Create_Strongly_Typed_View" width="509" height="502" class="size-full wp-image-10985" srcset="/wp-content/uploads/2015/11/Create_Strongly_Typed_View.png 509w, /wp-content/uploads/2015/11/Create_Strongly_Typed_View-300x296.png 300w, /wp-content/uploads/2015/11/Create_Strongly_Typed_View-400x394.png 400w" sizes="(max-width: 509px) 100vw, 509px" /></a><p id="caption-attachment-10985" class="wp-caption-text">Create_Strongly_Typed_View</p></div>
<blockquote><p>When you create a view as strongly typed view, your view header will be as follows. @model List<AsyncActions.Models.Customer></p></blockquote>
<p>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.</p>
<p>[html]<br />
&lt;link href=&quot;~/Content/bootstrap-theme.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
&lt;link href=&quot;~/Content/bootstrap.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
&lt;script src=&quot;~/Scripts/jquery-2.1.3.min.js&quot;&gt;&lt;/script&gt;<br />
&lt;link href=&quot;~/Content/Gridmvc.css&quot; rel=&quot;stylesheet&quot; /&gt;<br />
&lt;script src=&quot;~/Scripts/gridmvc.min.js&quot;&gt;&lt;/script&gt;<br />
[/html]</p>
<p><strong>Add the grid namespace</strong></p>
<p>You can add the grid namespace as follows.</p>
<p>[html]<br />
@using GridMvc.Html<br />
[/html]</p>
<p>Next thing is to add grid implementation.</p>
<p><strong>MVC Grid Implementation</strong></p>
<p>To add a MVC grid as our requirement, you need to add the codes as below. </p>
<p>[csharp]<br />
@Html.Grid(Model).Columns(columns =&gt;<br />
           {<br />
               columns.Add(foo =&gt; foo.CustomerID).Titled(&quot;Customer ID&quot;).SetWidth(50).Sortable(true).Filterable(true);<br />
               columns.Add(foo =&gt; foo.CustomerCode).Titled(&quot;Customer Code&quot;).SetWidth(50).Sortable(true).Filterable(true);<br />
           }).WithPaging(20)</p>
<p>[/csharp]</p>
<p>As you can see we are using the columns Customer.CustomerID and Customer.CustomerCode. </p>
<p><strong>Output</strong></p>
<div id="attachment_10986" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data.png"><img decoding="async" aria-describedby="caption-attachment-10986" src="http://sibeeshpassion.com/wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data-1024x518.png" alt="MVC_Grid_With_Dynamic_Data" width="634" height="321" class="size-large wp-image-10986" srcset="/wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data-1024x518.png 1024w, /wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data-300x152.png 300w, /wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data-768x389.png 768w, /wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data-400x203.png 400w, /wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data-1185x600.png 1185w, /wp-content/uploads/2015/11/MVC_Grid_With_Dynamic_Data.png 1918w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-10986" class="wp-caption-text">MVC_Grid_With_Dynamic_Data</p></div>
<p><strong>Add more Grid features</strong></p>
<p><em>To set the paging </em> we can use the option <em>WithPaging(20)</em>.<br />
<em>To add title</em> we can use <em>Titled</em> property.<br />
<em>To set width</em> we can use <em>SetWidth</em> property.<br />
<em>To set sort</em> we can use <em>Sortable</em> property.<br />
<em>To set filter</em> we can use <em>Filterable</em> property.</p>
<p>You can always see the additional options <a href="https://gridmvc.codeplex.com/documentation" target="_blank" rel="noopener">here </a>.</p>
<p><strong>Conclusion</strong></p>
<p>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.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>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.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://mail.sibeeshpassion.com/using-mvc-grid-in-mvc/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
