0

i have question about C# Controller. How to call inner class in C# Controller? For example, i wish to call AdminController.Inner.Call() from JavaScript.

    public class AdminController {

        public class Inner {

            public JsonResult Call() { }

        }

    }

Thanks for answers!

Everything what i read i know. This is just example, i need this for large project, about 3000 lines. If i have 5 functions for one page, i want to join it to one class, separately from others. And so others functions make same way.

MarTic
  • 665
  • 3
  • 10
  • 27

2 Answers2

1

Haven't used controllers before personally, but after a quick read it looks like a pretty restrictive type. If the whole issue is calling an inner class method, why not just write a method on the top level class that calls the inner class's method and returns it's return?

ex.

 public class AdminController {

    public class Inner {

        public JsonResult Call() { }

    }

    public JsonResult InnerClassMethod { return this.Inner.Call(); }


}

Duct tape isn't pretty, but it works.

boxed
  • 11
  • 1
0

Either write a custom ControllerFactory or call it using an ActionMethod from your AdminController:

public class AdminController 
{
    public JsonResult CallInner()
    {
        var inner = new Inner();
        return inner.Call();
    }        
}

It does seem like you're actually trying to do something else though, can you explain what?

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • I have large project and i need more classes under master class Admin. I reorganize code for better practice. Therefore i can join more function about one tema to one class, and so other. – MarTic Jul 18 '14 at 08:03