Sunday, April 27, 2014

ASP MVC

I have been trying out ASP MVC recently. Naturally, I hit a few roadblocks and found some solutions.

Init
Make sure you update your nuget packages after initializing the project.

Logging
I settled on using NLog. Darren has an entire series of blog posts on MVC logging.

Custom Model Binding and Validation
This is a great introduction, but I settled on the solution on Stack Overflow. Always use DefaultModelBinder over IModelBinder.

Passing Multiple Models into a View
Again, great article on SO. There are two main methods I considered: PartialViewResults and passing into a Tuple. The "tuple" method is very much a hack, and results in a bunch of issues if you need to display validation messages from the ModelState.

Routing
Article. Routing is ugly. Do the web a favor and set routes.LowercaseUrls = true; 

Custom Error Pages
After many hours of trying out different solutions, I am still stuck on this one.

Finally, stuff I liked:
- Script bundling and compression out of the box
- CSRF token and validation
- Model validation using data annotation attributes
- Nuget packages: MVC HTML5 Toolkit

No comments: