Getting current controller & action from within partial view

后端 未结 2 942
清酒与你
清酒与你 2020-12-23 22:29

I\'m using the following to get the current controller and action in asp.net MVC3:

var currentAction = routeData.GetRequiredString(\"action\");
var currentCo         


        
2条回答
  •  Happy的楠姐
    2020-12-23 22:54

    I stumbled on this page looking for a way to access the parent controllers name after a call using Partial

    @Html.Partial("Paging")
    

    This can be done in the partial view as

    @{
        var controller = ViewContext.RouteData.GetRequiredString("controller");
        var action = ViewContext.RouteData.GetRequiredString("action");
    }
    

提交回复
热议问题