4

I am trying to write some client validation in a class library. I added a reference to System.Web.Mvc on my local machine here C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll but I am getting the error

The type or namespace ModelClientValidationRule could not be found (are you missing a using directive or an assembly reference?)

I am targeting .Net Framework 4 and this MSDN link indicates that should be correct, so I am little stumped as the why the error is occurring.

I am using VS2013 and have .Net 4.5 on my local machine, and have written client validation in other projects. I expect that I could resolve this issue by adding the MVC NuGet package, but I would like to explore the alternatives.

1

2 Answers 2

9

While ModelClientValidationRule is in the namespace System.Web.Mvc, it is in the assembly System.Web.WebPages, so you need to reference that assembly too.

Sign up to request clarification or add additional context in comments.

3 Comments

For future reference: if you have a similar problem in the future look at the msdn page for the class you need it will name the assembly the class is in.
Please view grandhah.blogspot.in/2015/07/… I have explained the custom validation for data annotation
@NilsO: It is not always that easy (I wish it was) - in my case, the error occurred after doing a NUGET update of MVC - although System.Web.MVC.dll was updated, ModelClientValidationRule was no longer available. Referencing the old DLL fixes the issue, but I want to use the new one. I am still looking for a solution - no luck in MSDN or via Mr.Google so far. Similar question (no answer yet): here
0

In addition to Nils answer, you may need to add Microsoft.ASP.NET.MVC package from NuGet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.