Client-side validation with a model-less view in ASP.NET MVC 2 - asp.net-mvc-2

I'd like to use the new client side validation features in MVC 2 but I have a particular view that just has a couple textboxes on it and I don't want to create a strongly typed model for it. Can someone describe how to leverage the validation goodness in MVC 2 w/o a strongly typed model?

I don’t think it can be done as client side validation uses Data Annotations in the System.ComponentModel.DataAnnotations namespace. To my knowledge you have to bind this to an object. I would suggest looking at a jquery solution.

Related

how to use DataAnnotations in desktop application

When we are using EF (f.e.) via MVC, we can use ModelState.IsValid to detect a model can pass DataAnnotations metadata or not. But how can I use DataAnnotations metadata in a desktop (win-forms / wpf) application?
More:
In fact, I want to create an object same as ModelState (a dictionary that can save properties and messages associated with each). Then, wrap the DAL by a validation-layer, in VL use metadata to validate models, that the VL can be used in any project. I know I should use reflector, but I haven't any experience. Thanks to any help and suggestion.
If you are using EF 4.1/4.1 dbcontext, it has a built in validation API that can check Data Annotation rules as well as IValidatableObject.Validate. I'm not quite sure that I understand your goal, but if it is to have the validation in the data layer then you can just use what's built in. (Here's an overview http://msdn.microsoft.com/en-us/data/gg193959).
If you want your own validator that is separate from the data layer, then look at the System.ComponentModel.DataAnnotations namespace for methods and other logic you can leverage to do your own validation.

Is there a way to allow a user to submit html content while still enabling model validation?

I need to allow users to submit a form value containing html in their text inputs. This is an internally-facing application so it's reasonably safe to do so. I have succesfully used the
[ValidateInput(false)]
attribute on the method in question, but this inhibits all model validation for the method/view model in question, but I only want to allow html in one of the TextBoxes and do not necessarily wish to write my own guard clauses for every other piece of model validation in the same method/view model, when I could would prefer to continue using Data Annotations for all of the other properties in the view model.
It's too bad I cannot apply the [ValidateInput(false)] to only a single property of my viewmodel. I would assume that I need to override mvc's default model validation, but I cannot find any documentation on how to do so. Every search yields results describing only how to write my own custom validation attributes, which isn't correct for the problem I'm trying to solve.
Thanks!
You would have to upgrade your aplication to ASP.NET MVC 3. There you have AllowHtmlAttribute, which you can use to disable input validation on property level. ASP.NET MVC 3 is backward compactible with ASP.NET MVC 2 so the upgrade should be easy.

jqGrid vs. Html.Grid Helper

I have been using jqGrid as my grid view to my data for some time now. It works well and it was easy to implement into my solution. However, due to some refactoring going on within the project right now, I have been looking into it again.
The project itself is built around ASP.NET MVC 2 (.NET 4.0). We need some extra functionality such as:
Being able to add columns.
Inline editing of columns.
Sorting
Filter
Paging
Searching
jqGrid does all of this (although, not all of this functionality is implemented yet - some of it is new based on new needs). But, given that I am using ASP.NET MVC, I was wondering if it would make more sense to switch to the Html.Grid helper. It looks just as easy to implement for the things I know it can do (Sorting/Filtering/Paging), but I do not know if it can even do the other tasks (in a fairly straightforward manner) - anything I have found seems somewhat "hackish."
Can anybody enlighten me on A.) the capabilities of Html.Grid to jqGrid and B.) if there is any reason I'd want to take Html.Grid.
I use jqGrid successfully with ASP.NET MVC 2 (.NET 4.0) and have all the features which you describe in your question. Moreover all pages having jqGrid looks like very simple.
I don't use Html.Grid or any MVC controls. I include just pure HTML fragment <table id="list"></table><div id="pager"></div> on the page. Additionally I include the JavaScript which initialize the "list" table and the "pager" div as the jqGrid. So the implementation is independent from MVC concept. The most important part of the jqGrid integrations is the actions which get back pure JSON output and which implement GET/PUT/POST/DELETE operations with the jqGrid. You can read more about the approach here (see also many links with code examples included in the answer).
To be exactly I prefer to use WCF as a part on my ASP.NET MVC solution and the WCF methods provide the data needed for jqGrid (see here more details), but you can implement all as pure ASP.NET MVC actions.
If you use Unit testes for you ASP.NET MVC site you can successfully write tests for WFC methods or controller actions used by jqGrid. In the way you will test the most parts of jqGrid implementation.
After looking at both approach, I decided the jqGrid was a far easier (and simpler) approach for what I was attempting to do.

Looking for a technique to reduce "controller repetition" for CRUD operation in ASP.NET MVC

I am developing the administration part of a site. It mostly consist of manipulating list of data such as:
Products
Suppliers
Tax profiles
...
I find the task of creating a controller that handle the CRUD operations of each model a little too repeating and prone to mistake from one controller to another.
I would still need to adapt some of these controller for additional operation, but not all.
Does someone know a proven approach for reducing the implication of controller for the usual CRUD operations?
One suggestion would be to look at tweaking the T4 template that is used to generate the scaffold methods. Check out Rob Conery's MVC Starter Site to see what he's done (look in /Web/CodeTemplates in the source for the general idea).
There are also some other MVC libraries out there such as FubuMVC that aim to cut down on code repetition, but it's not based on the actual ASP.NET MVC framework (and it's not really my thing).

ASP.NET MVC 2 EnableClientValidation : validation group

I'm using ASP.NET MVC 2, DataAnnotation and MicrosoftMvcValidation.js for validation. I have two forms in my view..is there a way to use Validation Group for client side validation (like in ASP.NET Webforms).
thanks
The example I've seen with the nerd dinner (http://www.asp.net/mvc/videos/what-is-aspnet-mvc-80-minute-technical-video-for-developers-building-nerddinner) uses a partial class to modify the dinner model by adding validation to specific elements. This way validation can be handled at the server level but without server controls.
But... you can still use the validation controls with asp.net mvc if that's what you mean.
Did you mean to show summary of error(s)? If so you can use HTML helper for validation summary, like Html.ValidationSummary(...).
Hope this helps!