-1

I was working with a ModelState.AddModelError() recently. But there is a problem. I have 2 files in one when I type ModelState. intellisense shows the AddModelError() method. But in other file its not. I am getting the error there. ModelState.AddModelError() is defined in the System.Web.Mvc.Controller.The first file contains the Controller class within System.Web.Mvc. But I could not find Controller class in the second file even though its using System.Web.Mvc. Can anyone help with this?

Area51
  • 3
  • 3
  • Is the 2nd file a class which inherits `Controller`? Show your code. –  Dec 02 '15 at 06:08

1 Answers1

0

It doesn't use, it actually inherits from the Controller class. The one in which you could use that must be a Controller which inherits from the Controller parent class.

And the one in which you couldn't use that method must be some other class which obviously didn't inherit from the Controller class.

In order to use some of the functionalities including this, your class has to inherit the parent Controller class.

Hope this clears the idea.

Dhrumil
  • 3,221
  • 6
  • 21
  • 34
  • both files use that namespace `System.Web.Mvc` but on hovering , it shows the `controller` within it but not in the other file's `System.Web.Mvc` – Area51 Dec 02 '15 at 06:28
  • @Area51 - This is how both of your classes should look like : `public class AccountController : Controller`. It should inherit the `Controller` class. – Dhrumil Dec 02 '15 at 06:37