thoughts on coding

March 11, 2009

TT template for MVC Grid with ordering and paging

Filed under: .NET, ASP.NET MVC, MVCContrib, TextTemplate — Tags: , , — Frantisek @ 1:35 pm

In my previous posts I wrote about my extensions to MVCContrib grid like paging and ordering.

It’s tedious work to create the pages with the grid and define all the columns by hand. As you know from MVC RC1 it’s possible to use the TT templates to gerenate the views. I found a TT template fofr MVC Grid somewhere on the web and I extended it to generate the views using my extentions for ordering an paging.

Here is a screenshot from the template:

mvccontrib

When you copy such template to the folder:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC\CodeTemplates\AddView

then you will be able to use it in the dialog:

mvc_addview

and here is the result:

mvc_addview_result

While generating the view using the entities which are derived from some base class which is not in the same assembly as the entity, you can get the exception “Could not load type …”. You need to copy the base assembly to the location “C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\\” and then it starts to work properly.

Using such template mechanism the developer can create the lists, details, etc. very quickly . The heart of the whole process is TT template. Just briefly, there is quite exhaustive blog here regarding TT templates.

The template can be found here

March 5, 2009

ASP.NET MVC Pager

Filed under: .NET, ASP.NET MVC — Tags: , , — Frantisek @ 10:24 pm

Based on the feedback I’ve got I decided to write more about the pager I wrote in recent days. I use this control with MVCContrib Grid control.

The main difference is that my Pager control doesn’t required the IPagination interface.

You can call it like this:

<%=Html.Pager(Model.Search.CurrentPageIndex, Model.Search.MaxRowsPerPage, Model.Search.TotalRowCount)%>

That’s all and it will look like the following picture:

pager

The code can be downloaded from here The link points to the ZIP file which contains 2 files, both are extensions. When you want to use the pager you havet o reference latest MVCContrib library as the pager links are built using MVCCongrib.UI.Tags.Link class.

When I use MVCContrib library I use to add the namespaces to the web.config.  Just FYI: you need to add to web.config the following:

<add namespace="MvcContrib.UI.Pager"/>

That’s all for now. Next will be ordering :o)

Blog at WordPress.com.