0

I have several Controllers which all inherit a BaseController.

I have an Admin Area setup where Controllers inherit the BaseController. Inside the BaseController there is a method called public JsonResult DoSomething(). If some of these Controllers have a View of which a Url.Action is defined, how can I reference that DoSomething() method in the base controller with an Area reference?

BaseController
FruitController : BaseController
VegetableController : BaseController

Index View of FruitController has a call to

@Url.Action("DoSomething", ???, new { area = "Admin" })

I dont think there is a constructor with action and just variables. Am I just stuck with defining public JsonResult DoSomething() in each Controller regardless of it being in the BaseController as I can't seem to call the method.

4

1 回答 1

0

您调用DoSomething您当前所在的控制器..因为它继承了BaseController,它也将具有DoSomething操作。但是,它返回的视图必须位于正确的控制器视图文件夹下。否则您必须明确说明视图的位置。

@Url.Action("DoSomething", "Fruit", ...
于 2012-08-04T13:12:55.480 回答