ASP.Net MVC: Calling a method from a view

前端 未结 8 1261
轻奢々
轻奢々 2020-11-29 02:52

In my MVC app the controller gets the data (model) from an external API (so there is no model class being used) and passes that to the view. The data (model) has a container

8条回答
  •  一整个雨季
    2020-11-29 03:17

    This is how you call an instance method on the Controller:

    @{
      ((HomeController)this.ViewContext.Controller).Method1();
    }
    

    This is how you call a static method in any class

    @{
        SomeClass.Method();
    }
    

    This will work assuming the method is public and visible to the view.

提交回复
热议问题