Asp.net mvc 从htmlhelper中访问视图

Asp.net mvc 从htmlhelper中访问视图,asp.net-mvc,html-helper,Asp.net Mvc,Html Helper,我正在使用MVC4,并创建了一个自定义的HtmlHelper 是否可以从该助手中访问调用该助手的视图?我想在助手方法中使用基本视图中的属性。是的,您可以:) 您可以从视图将这些属性传递到HtmlHelper中吗? public static void MyExtension(this HtmlHelper html) { var view = html.ViewDataContainer; // accessing view properties var viewMod

我正在使用MVC4,并创建了一个自定义的HtmlHelper

是否可以从该助手中访问调用该助手的视图?我想在助手方法中使用基本视图中的属性。

是的,您可以:)


您可以从视图将这些属性传递到HtmlHelper中吗?
public static void MyExtension(this HtmlHelper html)
{
    var view = html.ViewDataContainer;

    // accessing view properties
    var viewModel = view.Model;
    var viewAjax = view.Ajax;
    // etc
}