Form input validation options in ASP.NET MVC 1.0+ - asp.net-mvc

A number of questions have been asked on this topic before, but since ASP.NET MVC is moving quite fast I wanted to re-ask the question:
What would you recommend for providing form input validation in ASP.NET MVC?
Requirements:
Server-side checking
Client-side (JavaScript) checking
Should cover the basics such as mandatory fields, numeric range validation, regex validation
(So basically all (or most) of the stuff that the ASP.NET WebForms validation controls do)
Current options seem to be:
Validator Toolkit on CodePlex
Jumping to ASP.NET MVC 2 Preview 1 (Our application is for internal use and go-live is in 6 months, so we might be comfortable using the preview)

xVal should be good choice in your case.

I would use DataAnnotations, is going to be a part of MVC but can be compiled and used in 1.0.
http://www.asp.net/learn/mvc/tutorial-39-cs.aspx
/M

FluentValidation also has an MVC component, however it doesn't do the client side of things. Ideally this could be integrated with xVal.

Related

ASP.Net MVC or Web forms which is better

I am going to start work on a SaaS based application. I need to decide whether to go with ASP.Net MVC or web forms application. Through various posts I came to know that both are good, they are not replacement of each other and so on.
Also, I know traditional web forms method, I am not aware of MVC, I need to learn it first.
Please guide me which approach is better.
Thanks,
Vijay
i can just share some of my experience as i have worked on both
i preffer asp.net MVC over Asp.net because of the futile layer of abstraction that Asp.Net has over basic HTTP architecture
the user controls in asp.Net induce unnecessary markup
ease of using ajax in asp.net mvc compared to updatepanel(in advanced senarious)
support of razor type syntax increases productivity
no overloading by things like viewstate
because everything is managed by the programmer soem of the typical issues that arise in asp.net like the problems in dynamic controls are no longer present
so if you ask me go for asp.net MVC
There is no right answer here. I prefer MVC but if you already know ASP.Net WebForms it probably is easier to stick with that.

Is xVal obsolete with MVC 2?

Now that built-in validation is supported with MVC 2 framework, should we be using it instead? Are there any advantages that xVal has over MVC 2 validation?
The main reason I ask is that we have a couple MVC sites that use it, and it appears xVal is no longer being maintained/supported. If this is the case, I'd like to start changing our sites over to use MVC 2 validation.
Thanks in advance.
The jQuery validation scripts included with MVC2 are fully supported by Microsoft, so I would prefer them over third-party scripts, especially ones that no one is actively supporting. The xVal Codeplex site clearly lists xVal as only supported with MVC1.0.

ASP.NET MVC vs. WebForms - a simple question

I'm wondering about one thing - as we know, the MVC pattern is stateless (it doesn't use the ViewState, so we use only HTML controls), but if we use them in WebForms as well, it'll become stateless too ? so, by doing this, we are getting closer to the MVC pattern ?
You get closer to one aspect of MVC i suppose but its still a night and day difference.
MVC is fundamentally about the model view controller pattern, not what kind of controls your using to write your code. Unless you implement an MVC pattern within webforms (which people did a lot before ASP.NET MVC was released) and migrate away from the postback model in webforms then your platform is still considerably different.
If you want to do that then just use ASP.NET MVC.
ASP.NET WebForms is stateless too. All HTTP communications are. ViewState is just a way of preserving some state by hidden form fields which' values are encoded.
There is nothing stopping you creating your own hidden fields in MVC to make it 'kinda stateful'.
No we don't use HTML controls in ASP.NET MVC. We use HTML helpers. There's a big difference.
I think you're confused about what stateless means. All web development is stateless, in so far as the server sends down a page to the client and then forgets about it.
.NET tries to make it "easier" by using ViewState and Session, but MVC and Web Forms are stateless.
MVC is an architectual pattern. It can be implemented in any language/framework/environment (although some make it easier than others.)
I don't know why you would attempt to apply MVC to webforms when all the work has been done for you by Microsoft to implement MVC in ASP.NET with ASP.NET MVC...
As with any software models, there isn't necessarily a hard-defined line between fundamental principles. I've been developing applications with loose implementations of MVC in WebForms for years.
The lack of pseudo-state (I won't give WebForms the credit for actual state, the web is stateless) in MVC is one of a number of aspects of the ASP.NET implementation of it, it is not part of the actual MVC pattern.
On top of all this, I can see why people miss Web Controls and want to use them in MVC. But why would you want to use HTML helpers in WebForms? If you're willing to do this type of groundwork then you probably should be using MVC.

Validation Framework for a WPF app (using MVP) and ASP.NET MVC

I'm looking for a form validation framework that works best in both Windows (WPF using MVP) and Web (ASP.NET MVC).
I'm currently looking at three choices:
Enterprise Library Validation Application Block
http://www.codeplex.com/FluentValidation
http://validationframework.codeplex.com
I like Fluent Validation as it looks a lot cleaner. The others, though, have been around longer.
Any other recommendations?
In MVC apps I've found Fluent Validation very useful for more complex validations. DataAnnotations are often enough for simple validations in MVC.

How do you go about validating check boxes in ASP.NET MVC?

I am wondering what methods people are using for validating check boxes in ASP.NET MVC (both client and server side).
I am using JQuery currently for client side validation but I am curious what methods people are using, ideally with the least amount of fuss (I am looking for a new solution).
I should mention that I am currently using MVC Preview 4, and while I could upgrade to MVC Preview 5 if there is no elegant solution in MVC Preview 4, I would prefer not to at this stage just for compatibility purposes with other developers and existing solutions.
Note, I have seen these related posts:
Validating posted form data in the
ASP.NET MVC framework
What’s the best way to implement field validation using ASP.NET MVC?
MVC.net JQuery Validation
If you go on to the validation website and download the whole package that included the demo files, you can find the one with example of validating check boxes and radio buttons.
The link is here:
http://jquery.bassistance.de/validate/jquery.validate.zip
I assume you simply check whether or not the name of the checkbox was posted to the server or not. Not being an ASP coder myself, I can't help, though this is how it would be done in PHP (of course, depending on how you map validations).
<?php echo isset($_POST['checkbox_name']) ? 'checked' : 'not checked'; ?>

Resources