amateur
amateur

Reputation: 44605

access view from within htmlhelper

I am working with mvc 4 and have created a custom HtmlHelper.

Is it possible from within that helper, to access the view that is calling the helper? I want to use properties that I have on the base view within my helper method.

Upvotes: 0

Views: 115

Answers (1)

Sławomir Rosiek
Sławomir Rosiek

Reputation: 4073

Yes, you can :)

public static void MyExtension(this HtmlHelper html)
{
    var view = html.ViewDataContainer;

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

Upvotes: 2

Related Questions