MVC3 Razor

TwitterFacebook
Get flash to fully experience Pearltrees

Custom Data Annotations With MVC: How to Check Multiple Properties at One Time | Programming By A Tool

http://byatool.com/mvc/custom-data-annotations-with-mvc-how-to-check-multiple-properties-at-one-time/ Ok so maybe you read this post and you’re thinking to yourself, “I wonder if Diet Dr. Pepper really does taste like regular Dr. Pepper” which of course is silly because the ads clearly say it does. Now you should be asking yourself, “How do I check if two properties have the same value on a class with annotation when the property level ones only can check the one property’s value?” Kind of wordy way of asking that, but I get what you’re asking. Better yet, like usual, I have an answer.
The validator we looked at in the last post only supports server side validation. To support client side validation we need a little more code on the server, and some custom client script. One approach to client validation is to have the validation attribute implement the IClientValidatable interface, which requires a single method: GetClientValidationRules. public class DateGreaterThanAttribute : ValidationAttribute , IClientValidatable { public IEnumerable < ModelClientValidationRule > GetClientValidationRules( ModelMetadata metadata, ControllerContext context) { var rule = new ModelClientValidationRule (); rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()); rule.ValidationParameters.Add( "other" , OtherProperty); rule.ValidationType = "greaterdate" ; yield return rule; } // ...

Custom Data Annotation Validator Part II: Client Code

http://odetocode.com/Blogs/scott/archive/2011/02/22/custom-data-annotation-validator-part-ii-client-code.aspx

Custom Data Annotation Validator Part I : Server Code

http://odetocode.com/blogs/scott/archive/2011/02/21/custom-data-annotation-validator-part-i-server-code.aspx Let's say you want to create a GreaterThan validation attribute and use it like so: public class Trip { [ Required ] public DateTime StartDate { get ; set ; } [ Required ] [ GreaterThan ( "StartDate" )] public DateTime EndDate { get ; set ; } } The implementation would look something like this: Notice the IsValid override available in .NET 4 adds a ValidationContext typed parameter, and this parameter makes it easier to look "outside the attribute" at the associated model type and model instance (validationContext.ObjectType.GetProperty(OtherProperty)). The validation context does have a shortcoming when it comes to model metadata, however.
http://blog.toddbauer.me/2011/06/01/uploading-files-in-asp-net-mvc/ If you’ve tried creating a form that includes a file upload, you might have run into a problem of having a null value for the posted file in your controller’s action method. Take the following (Razor) view that accepts a string and a file upload as an example: Now, assume the following action method on your controller class: When we run this code we’ll find that the fileUpload variable that’s passed into our controller method is null even though the someString value is populated as expected. Why?

Uploading files in ASP.NET MVC « Todd On .NET

ASP.NET MVC3 has been a major boon to my productivity as a web developer since I started using it at the beginning of November – the new Razor view engine has been attracting most of the attention with this iteration of MVC, but one extremely sexy feature has gone unnoticed thus far: Remote validation . Remote validation was one of the new features added in the November Release Candidate (RC) for MVC3 – I had a chance to demo it in front of the LA .NET User Group last night and it was a monster hit. Example:

Aaronontheweb | How-To: Remote Validation in ASP.NET MVC3

http://www.aaronstannard.com/post/2010/12/07/remote-validation-asp-net-mvc3.aspx
One validation feature that we didn’t quite have time for in MVC 2’s new client-side validation support is called “remote validation”. Remote validation means we make a call back to our web site to ensure that a given value is valid. You might want this in cases where it’s not easy (or possible) to determine whether the value is valid on the client side, but you’d still like to give the user client-side feedback about the validity of the item. The canonical example is checking to see if a desired username is taken during your site registration process. This is an example remote validator that I modified from an example by Levi Broderick (who did the bulk of the JavaScript work for client-side validation).

Brad Wilson: Remote Validation with ASP.NET MVC 2

http://bradwilson.typepad.com/blog/2010/01/remote-validation-with-aspnet-mvc-2.html
Partial Views

Links FileUpload

http://www.asp.net/mvc/tutorials/older-versions/javascript/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript Home / MVC / Tutorials / Chapter 10. Older Versions / JavaScript / Creating a MVC 3 Application with Razor and Unobtrusive JavaScript The User List sample web application demonstrates how simple it is to create ASP.NET MVC 3 applications using the Razor view engine.

Creating a MVC 3 Application with Razor and Unobtrusive JavaScript

Two weeks ago we shipped the ASP.NET MVC 3 Beta Release . It supports “go live” deployments, and includes a bunch of nice improvements/enhancements. You can see a summary of the new ASP.NET MVC 3 features in my beta announcement post . Also read my original ASP.NET MVC 3 Preview post to learn about other ASP.NET MVC 3 features that showed up with that initial preview release. http://weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx

MVC 3: Layouts with Razor

http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx One of the things my team has been working on has been a new view engine option for ASP.NET. ASP.NET MVC has always supported the concept of “view engines” – which are the pluggable modules that implement different template syntax options. The “default” view engine for ASP.NET MVC today uses the same .aspx/.ascx/.master file templates as ASP.NET Web Forms.

Introducing “Razor” – a new view engine for ASP.NET

(includes April 2011 Tools Update) ASP.NET MVC 3 is a framework for building scalable, standards-based web applications using well-established design patterns and the power of ASP.NET and the .NET Framework. It installs side-by-side with ASP.NET MVC 2, so get started using it today!

MVC 3