Problem with DataAnnotationsModelBinder in ASP.NET MVC 2 - asp.net-mvc

Everybody tried out a tutorial on DataAnnotations from mvc official website? It didn't work for me.
When I'm trying to submit edited product, I have this error message:
Method not found: 'System.Collections.Generic.IDictionary`2 System.Web.Mvc.ModelBindingContext.get_ValueProvider()'.
I'm using ASP.NET MVC 2 preview 2. Any ideas why this happening? I registered model binder which they required.
May be someone came across a post or article that had a guide how to get this to work?

The DataAnnotations model binder is the default model binder in ASP.NET MVC 2, you shouldn't have to register the model binder as it does in the tutorial. So remove the line where you register the model binder.
Also, while you're at it, you should probably update to the ASP.NET MVC 2 Beta.
HTHs,
Charles

Related

ASP.Net MVC is it passive model or active model

As the subject states, is the mvc model that is used in ASP.Net MVC an active or passive model and why.
#joa. I've read up on the website at the link provided and you are indeed correct.
VS2010 creates a passive asp.net mvc project for you. Its then up to you to modify it into an active mvc model.
By default dev's go along with the passive model (looking at the many, many examples of asp.net mvc). Implementing the active model requires a bit more work though.
Ref: http://martinfowler.com/eaaDev/uiArchs.html

Where can I find a decent tutorial/explanation of using Castle Validators with ASP.NET MVC2?

Where can I find a decent tutorial/explanation of using Castle Validators with ASP.NET MVC2?
I want to go with Castle because I'm not fond of the fact that I can't test my POCOs using Data Annotations without copying the logic of grabbing the attributes and calling isValid on all of them. I'm much more fond of the fact that with Castle I can just call IsValid on the ValidatorRunner which I can instantiate in my tests. I might just forget about the built-in mvc2 validation framework and go with xVal. /shrug
These articles/screencast seems to be good:
ASP.NET MVC Auto Model Validation with xVal
Model-based Client-side Validation for ASP.NET MVC
Contact Form with ASP.NET MVC, Castle Validation, & fluentHtml
Hope that helps.

how-to enable Client-Side validation fora textbox

how-to enable Client-Side validation for a ordinary textbox in ASP.NET MVC.
Scott Guthrie just published a good article on validating models -- and you should think about it as model validation, not textbox validation -- in ASP.NET MVC 2.0. You might want to check out how they do validation in the NerdDinner example at http://nerddinner.codeplex.com/.
There are various options. If you are using MVC 1 you might want to read this article http://blog.codeville.net/2008/04/30/model-based-client-side-validation-for-aspnet-mvc/. If you are using MVC 2, using DataAnnotations, which has the option of validating on client side.

What are validation options for ASP.NET MVC

What are my validation options with .net mvc?
Do any of them have a nice validation summary like webforms did?
You can use a MVC html validation summary,see this blog
http://blog.maartenballiauw.be/post/2008/08/29/Form-validation-with-ASPNET-MVC-preview-5.aspx
xVal is the best one. We implemented in three web applications and we will use it in many more in the future(until we find a better one than this). Check the details of xVal here
http://blog.codeville.net/2009/01/10/xval-a-validation-framework-for-aspnet-mvc/

How do you do validation in ASP.NET MVC RC?

Does ASP.NET MVC provide a standard validator functionality or do you have to create your own validation manually? If the latter, is there any third party validator available that you can use on ASP.NET MVC web applications?
Shortly after I posted this answer I found xval which is a validation framework for ASP.NET MVC.
ASP.NET MVC contains methods like Html.ValidationSummary() and Html.ValidationMessage(). These are updated automatically if you use TryUpdateModel. You could also validate manually and set the errormessages yourself. Here is an example of how use it.
David Hayden wrote an article over at www.codebetter.com describing a great way to handle validation. Of course xVal is an option but it's always great to have an understanding.
I implemented a variant of the code I found on Stephen Walther's blog. I use it with LINQ2SQL models by defining an IValidatedEntity interface that includes the GetRuleViolations() method and implementing the partial OnValidate method that calls GetRuleViolations() and throws a custom exception if the number of violations is non-zero. In the controller, this fires on SubmitChanges for the data context. If I get an exception I requery the model via the GetRuleViolations() method to build model errors to pass back to the view.
You can also checkout the .net validation framework. Its a rules framework that lets you create validators, apply the validators to rules, attach rules to your model, and check those rules at runtime on both the client and server. It provides flexible ways to configure rules - making heavy use of linq for both fluent and strongly typed configuration. It also provides extensibility points to create your own client script generators and rules.
The framework leverages the MVC RC HtmlHelpers and default conventions.
If you download the latest source you can see an example of the framework working in the SplitBranch -> QSAspMvc quickstart project. Its still being actively developed.

Resources