ASP.NET MVC 5 with Razor Kendo UI: Dynamic Grid Creation – Columns, Ordering, Grouping and Paging

The requirements were simple! A grid that will load a whatever query, grouped by whatever columns, with filters enabled, paging and everything. Easy task with ASP.NET Telerik grids but not easy at all with Kendo UI!

Since we can’t have a ViewModel or Model for the grid (we don’t know what columns a whatever query has!), I came up with a rather different ViewModel that holds descriptions for columns, groups etc…:

    public class WhatEverQueryModel {
        public DataTable Data { get; set; }
        public List<string> Groups { get; set; }
        public Dictionary<string, System.Type> Bind { get; set; }
    }

Continue reading

Advertisements

ASP.NET MVC 5: Custom authentication with OnActionExecuting

Although i prefer the AuthorizeAttribute solution, there is an other simpler way with a base Controller and OnActionExecuting:

Let’s assume the following Controller:

 

public class MemberController : Controller {
    public ActionResult Index() {
       //Stuff for members only
    }
}

Continue reading

ASP.NET MVC 5: Validating a VAT with ValidationAttribute and EU checkVatService

Validating a VAT with ValidationAttribute and EU checkVatService can be done very easily in a different assembly for using it in all your projects.
Just create a new project (I named it VAT) and follow these steps!

Step 1, add the service refenerence to your project
Right click on References and choose Service Reference. Paste this address http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl type your namespace (I use checkVatService) and hit OK
Continue reading

ASP.NET MVC 5: Custom AuthorizeAttribute for custom authentication

In my previous post, I wrote about how to protect your web app from human errors by enforcing authentication by default.

Since that process involves global filters, you can use that to add your own custom authentication by extending the AuthorizeAttribute.
Continue reading

ASP.NET MVC 5: Secure your web app

Securing your MVC app is one of the tricky things when migrating, as an engineer, from classic ASP.NET to ASP.NET MVC.

By default, access is allowed to every controller and action of your web app, which is potentially unsafe. As an architect, I am sure you would like to enforce the security of your app and don’t rely on whether a developer will actually remember to add the [Authorize] attribute to a sensitive controller or action.
Continue reading