ASP.NET MVC 3 Service Location, Part 4: Filters. Disclaimer This blog post talks about ASP.NET MVC 3 Preview 1, which is a pre-release version.
Specific technical details may change before the final release of MVC 3. This release is designed to elicit feedback on features with enough time to make meaningful changes before MVC 3 ships, so please comment on this blog post or contact me if you have comments. Location: Filter Providers Filter providers are a new feature to MVC 3. By default, there are three filter providers registered into the application: A filter provider for global filters (GlobalFilters.Filters)A filter provider for filter attributes (FilterAttributeFilterProvider)A filter provider for controller instances (ControllerInstanceFilterProvider) In addition, the GetFilters facade method will also retrieve all the IFilterProvider instances in the service locator by calling MvcServiceLocator.Current.GetAllInstances<IFilterProvider>(). Editing a variable length list, ASP.NET MVC 2-style. Download the demo project or read on for details.
Update (Feb 11, 2010):Thanks to Ryan Rivest for pointing out a bug in the original code and providing a neat fix. ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries. What are your favorite Nuget MVC packages » BuildStarted.com. Automatically instrumenting an ASP.NET MVC3 app. Update: There is now a nuget package that will take care of wiring this up automatically see: MiniProfiler seems to have upset quite a few people.
One major complain we got when Scott Hanselman blogged about it, goes: Why do you expect me to sprinkle all these ugly using (MiniProfiler.Current.Step("stuff")) throughout my code. This is ugly and wrong, profilers should never require you to alter your code base. FAIL. " Our usual retort is that you are able to properly control the granularity of your profiling this way. That said, I agree that sometimes it may seem tedious and unnecessary to chuck using statements where the framework can do that for us. Here is a quick document on how you can get far more granular timings out-of-the-box without altering any of your controllers or actions. Profiling Controllers Automatically wrapping your controllers with MVC3 is actually quite trivial, it can be done with a GlobalActionFilter.
Diving into ASP.NET MVC 3 Model Metadata Providers. ASP.NET MVC 2 Templates, Part 1: Introduction. Series Index Introduction to Templates One of the major new features in ASP.NET MVC 2 is templates.
This is a feature that’s similar to Dynamic Data for WebForms. Given an object of a given type, the system can automatically display or edit that object, whether it’s a simple data item (like an integer, a decimal, a string, etc.) or a complex data item (like a class). Conditional Validation in MVC. Update: If you like this, you'll like Mvc.ValidationTookit even more - check out this post!
Recently I put together samples for different types of validation for some customers, and one of those was Conditional Validation – that is “this field is required if another field is true”, and such like. But a few weeks later I saw my code fail! I got home and tried to reproduce it, and couldn’t… So this blog post is a sorry tale of how I spent hours and hours trying to work around my own dumb mistake. Huge thanks go to Stuart who didn’t call me too many names for wasting both our time J The Approach Fundamentally the approach to getting conditional validation working is to use the Validator and the Attribute in tandem. The problem you initially come across with validating based on the content in another field is that the signature of the Attribute’s IsValid method looks like this; public override bool IsValid(object value) This actually receives the whole entity being validated.
Easy as pie, huh? Eagerly Performing ASP.NET MVC 3 Unobtrusive Client Side Validation - Imran Baloch's Blog. Unobtrusive client side validation is one of the great feature that I like in ASP.NET MVC 3.
Unobtrusive client side validation feature uses the famous jQuery validation plug-in internally. Jquery validation plug-in perform client side validation lazily. What does this means? This simply means that before submitting the form for the first time, the user can tab through fields without getting any error message. Flexible Conditional Validation with ASP.NET MVC 3. UPDATE: I've now blogged the follow-up post on adding client-side support My colleague Simon and I have each written conditional validators with a number of customers, and Simon has blogged about it a number of times.
I’ve had another idea in this space that I’ve been meaning to post for a while. Simon’s most recent post gave me the nudge I needed, so if you haven’t read Simon’s post then now would be a good time – I’ll be building on the general concept here and showing a similar idea. The RequiredIf validator is applied to a property to indicate that it is a required field subject to some other condition. To illustrate, consider the following view model: Here we can use the RequiredIf attribute to indicate that the Comments field is required, but only when the IsComplete property is set to true – the first parameter to RequiredIf is the property name (“IsComplete”) and the second is the value to match against (true). All this got me thinking about how else this could be achieved… Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications.