-
Notifications
You must be signed in to change notification settings - Fork 2.1k
WebApi MVC 6 Model State Methods missing ex: ModelState.IsValid and AddModelError #3315
Comments
The methods are still there, and have pretty much always been there: |
@Eilon I should have mention that I do have the dependency Microsoft.AspNet.Mvc.ModelBinding; but its still giving me the error. My class consist of and none of these are working. |
Is your controller type deriving from |
Hover over the |
Also, you shouldn't have to import any namespaces to access that. If you're in a controller, you have access to it. |
@pranavkm I thought that in MVC 6 there is no need for base controller classes. I received that information from a video here. https://channel9.msdn.com/Events/dotnetConf/2014/MVC-6 @Eilon I went into the definition. ModelState is using the Controller class in the namespace Microsoft.AspNet.Mvc |
Ok Thanks @Eilon and @pranavkm I had to add Microsoft.AspNet.Mvc.Controller as a base controller. If I were you guys. I would really look at taking that video down because it clearly states that in MVC6 a base class is not required. If it is required and I just misheard it wrong. The video needs to be more clear at explaining the "why". Thanks! |
It's not required, but if you want to use |
@Muchiachio I guess |
I am converting a ASP 4 Web Api 2 to the new Asp.Net 5. After removing the old System.Web.Http and System.Web.Http.Description and replacing those NameSpaces with Microsoft.AspNet.Mvc. Now on a simple route in my controller. I am getting an error ModelState does not contain a definition for IsValid.
if (!ModelState.IsValid)
return new HttpStatusCodeResult(305);
This also happens in ModelState.AddModelError
The text was updated successfully, but these errors were encountered: