Retrieve the current view name in ASP.NET MVC?

后端 未结 10 886
谎友^
谎友^ 2020-11-28 09:37

I have a partial view (control) that\'s used across several view pages, and I need to pass the name of the current view back to the controller - so if there\'s e.g. validati

10条回答
  •  没有蜡笔的小新
    2020-11-28 10:29

    If you just want the action name then this would do the trick:

    public static string ViewName(this HtmlHelper html)
    {
        return html.ViewContext.RouteData.GetRequiredString("action");
    }
    

提交回复
热议问题