Thought I would share some code with my fellow MVC .net developers

Soldato
Joined
27 Mar 2003
Posts
2,708
So over the past 12 - 15 months I have been making the transition from webforms to MVC and although I wouldn't consider myself a complete MVC developer yet I have picked up so much over this journey.

Some of the great things that I have had the pleasure to use are Twitter's Bootstrap framework and Telerik's Kendo UI toolsets, these have made so much of the crud work enjoyable. Although these tools give me a nice quick way of setting up sites and getting something that looks nice in a matter of hours rather than days (I'm not the greatest designer) and to top it of my lack of jquery and javascript skills have improved so much by using both these products.

But one thing has irritated me in this modern web world is the default

@Html.ValidationSummary() helper

After spending the time to make my site look really nice I am left feeling frustrated at the lack of improvement that MS has done on this helper (having found loads of other developers looking for solutions on the likes of stackoverflow and not really finding anything that works for me).

So I thought I would take some time and make a bootstrapped version that can be customised to show the standard viewmodel errors but also custom errors that are added to the modelstate.

So I have put a project on github to hopefully provide something that is more in keeping with a bootstrap themed site (but can be customised to take other custom classes)
https://github.com/JellyMaster/MVCBootstrap

wiki (with some images of how this thing looks)
https://github.com/JellyMaster/MVCBootstrap/wiki/BootStrapped-Validation-Summary

So please feel free to try it out and let me know if I am doing anything horrendously wrong or could do something better.

I wanted something that was simple to implement but gave the developer (i.e me) a way of customizing the look and feel if required.

In addition I also added a simple way to indicate required fields as this was something that I miss from the webform days but didn't want to have to rewrite the same code over and over again for view models.

(I'm still not happy with how this works but I would be grateful for pointers to make this function better.)

Thanks for taking the time to look and if you think it will be of use to you please share.
 
Associate
Joined
7 Nov 2013
Posts
255
Location
Kent, England
I'm currently working on an MVC website, when I get onto the web page development I'll be sure to take a look at what you've done :)

However I'm not too sure how helpful my critique will be; up until recently I've primarily been a WCF developer with a bit of WPF work, but I'll take a look anyway.
 
Soldato
OP
Joined
27 Mar 2003
Posts
2,708
Not a problem. I should be pushing an update shortly to fix a minor issue I picked up today with model errors.

The only thing I haven't sorted yet is compatibility with jquery validate/ unobtrusive validate so that's next on the list of possible updates. But I think it covers most scenarios or at least the ones I could think off.


edit: So I have added unobtrusive support now. It does require one change to the unobtrusive file to restyle the li items but should be working correctly. The only mode the summary won't work in in unobtrusive mode is Modal as I need to think about how to get this working correctly.


edit2: So I had a thought about the way I implemented the unobtrusive support and wasn't happy with it so I have removed this for now until I can come up with a better solution.
 
Last edited:
Soldato
OP
Joined
27 Mar 2003
Posts
2,708
My preferred method is use the [Required] DataAnnotation for viewmodels within the form and then any additional errors that occur server side are just attached to the modelState.

I have now created a nuget package which should help get this installed quicker.

I have also updated the project home page to give people a cleaner step by step setup.
 
Soldato
OP
Joined
27 Mar 2003
Posts
2,708
No it doesn't at the moment.

That is the next thing I want to look at.

I am trying to think about the best way to do this at the moment.

This is the second time someone has suggested to me to use/look at that unobtrusive library so I may take a peak and include support for it or alter it for my needs.

As with my code I want something that works out of the box but can be customized by the end user if needed with their own css classes, text etc.

Hopefully you at least found it useful as a starting point for your project.

As I said I am open to ideas and improvements.
 
Associate
Joined
7 Nov 2013
Posts
255
Location
Kent, England
I've been playing around with AngularJS for the last few days, I'm absolutely loving it so far.

From my limited understanding, as long as you are using html5Mode, googlebot will be fine (it executes Javascript), I'm not too sure about other crawlers however.
 
Soldato
OP
Joined
27 Mar 2003
Posts
2,708
are people still using MVC these days?

web API & angularjs really.

For those of us who are still getting used to this modern web world the MVC helpers provide a convenient way of getting sites up and running quickly and not have to write too much html/javascript to get functional sites that work well.

I like creating MVC helpers/ extension methods for doing a lot of common tasks that I keep creating over and over again. I know some of the things are available via nuget that I have written but it allows me to learn new things while I am doing this and test out my skills and fill in any blanks when things don't go like I expect.

I am sure angularjs has it's place in the world but doesn't knockout, moustache, ember, backbone et al do similar things (maybe over simplifying here so apologies in advance).

It's great having all these javascript frameworks but for someone who isn't a strong javascript programmer (it's times like this that I curse my reliance on webforms for most of my development career) there just isn't the time to learn these things to a level that I would consider acceptable for my line of work.

Maybe with the changes that seem to be occurring in the MVC.net world around the corner (project helios) maybe these frameworks will become more important to me but for now I am happy with the MVC helpers that I use from Microsoft, Telerik, nuget and my own.

I personally see webApi being more important to me in future projects but again right now it's not a requirement and given that I have a WCF background this should be easy enough for me to transfer my skills to the modern web.
 
Soldato
OP
Joined
27 Mar 2003
Posts
2,708
Thanks for the info.

Hopefully you have managed to implement my little library successfully even in this fairly raw state.

I'll have a look then next time I start a MVC 5.2 project.

I'm not sure if their implementation goes as far as mine does in terms of customization but it is nice to see that the MVC team are working on things like this finally. It may seem trivial to many but it has always irritated me.
 
Back
Top Bottom