Telerik Mvc Grid Extension Method to highlight InActive record
I was recently working on a project where in there was a requirement that all those grid rows which are inactive in database should be highlighted with a different colour. In this project we were working with Telerik Mvc extensions.
I googled for this, and most of the responses were like, to add a client side RowDataBound event to each of the grid & place the logic there.
According to me this is a bit of time consuming tasks. So after some research & a bit help from telerik MVC forums, I created my own extension method to highlight the grid row for which the column value of the IsActive column is false.
In our database, each of the table contains a column “IsActive” which stores a Boolean value “true” or “false” so as to represent the particular record is Active or not. A record with false value in “IsActive” column indicates that the record is InActive.
Here are some simple steps to achieve this.
- First we need to write an extension method which will add a handler to highlight the record. Here is the code snippet for that
2. Add following class to CSS
4. Append your grid like this
And that’s all we need to do the row will be highlighted like this
You can find the source code here
Upgrade Application from Asp.Net MVC2 to MVC3
It’s been a much long after MVC3 is been released & now it is much stable. So while working on a project, I need to upgrade my ASP.Net MVC 2 project to MVC 3.
ASP.Net MVC 3 can be installed side by side ASP.Net MVC 2 on you PC, which gives you flexibility in choosing when to upgrade an MVC2 application to MVC3. It is been very easy to upgrade the project to MVC3. We just need to follow following steps
- Remove all references of System.Web.Mvc from each project in solution.
- Now add a reference for System.Web.Mvc 3.0 to each of the project in the solution.
- Also add a reference of System.Web.Helpers 2.0 to web project.
- Also add a reference of System.Web.WebPages 2.0 to web project.
- Go to views folder & open the Web.Config file & replace Version = 22.214.171.124 with version 126.96.36.199
- Also add following code to this Web.Config
- Open the root Web.Config file & replace all references of “System.Web.Mvc 188.8.131.52” with “System.Web.Mvc 184.108.40.206”.
- Now in appSettings add following keys
- Now we need to make sure our system.web->pages->namespaces tag contains following entries
- In the system.web->compilation->assemblies we should have following entries
- Finally under the configuration -> runtime section put following code
Yuhu……………! Here we are. Now just compile & run your code. Now it will run on MVC3. Also we need to make sure we are targeting .net Framework 4.0 while upgrading the MVC2 application to MVC3.
Also there is a tool available to upgrade the MVC2 to MVC3. Here is a link to the tool
You can find the source code here.
ASP.Net MVC & Multiple Submit Button
While developing any web applications we use to design lot more forms. Most of the times a form perform a single action, posting data to some controller. There is no necessity that each of the form will contain only a single submit button. Sometimes, we may need a form which will contain multiple submit buttons. As in the following case
So in this case, our form will be posting data to a single action Post but it contains 2 different submit button. So to handle this scenario, we need to code something like this in our controller.
Also this looks very simple when we have a simple Action, think how about doing this on a form of 10 fields & 4 buttons.
How if I am able to specify the name of the button near the action method wherein I will specify the name of the button on which that action needs to be invoked. We can achieve this in Asp.Net MVC by using the ActionMethodSelectorAttribute attribute. Here is a code snippet to show the use of the attribute
The ActionMethodSelectorAttribute is executed before the Action is executed, so we here we can check which button is clicked while submitting the form using the Form NameValueCollection object on the IsValidForRequest event of the ActionMethodSelectorAttribute.
Here is the implementation code for the class.
You can download the source code here.
This is my first post about ASP.Net MVC 4. I will be providing some links for ASP.Net MVC 4 which includes information about downloading & installing ASP.Net MVC 4.
ASP.NET MVC 4 NuGet Packages
One good news is that MVC 4 is also available via NuGet. To install MVC 4 via NuGet, type following in the Package Manager Console.
For more detail regarding NuGet package please visit http://www.nuget.org/List/Packages/AspNetMvc
ASP.NET MVC 4 for Visual Studio 2010
If you are using Visual Studio 2010 then you can use MVC 4 with Visual Studio 2010. To install MVC 4 via Web Platform Installer for Visual Studio 2010 please visit following link.
ASP.NET MVC 4 for Visual Studio 11 Developer Preview
If you are using Visual Studio 11 Developer Preview then you can install MVC 4 in Visual Studio 11 Developer Preview via following link.
ASP.NET MVC 4 Direct Download Link
For Visual Studio 2010, first you need to install Visual Studio 2010 SP1 KB983509 viahttp://download.microsoft.com/download/2/3/0/230C4F4A-2D3C-4D3B-B991-2A9133904E35/VS10sp1-KB983509.exe
MVC 4 Direct link for Visual Studio 2010 http://download.microsoft.com/download/E/D/7/ED7CB028-2CBD-4E26-87D5-C9164A0B4849/AspNetMVC4VisualStudio2010Setup.exe
MVC 4 Direct link for Visual Studio 11 Developer Previewhttp://download.microsoft.com/download/E/D/7/ED7CB028-2CBD-4E26-87D5-C9164A0B4849/AspNetMVC4VisualStudio11Setup.exe
Here are some useful links about MVC4