2

Using this stackoverflow thread, I created an extension for my HtmlHelper

How can I create a Html Helper like Html.BeginForm

My problem now is, I created a custom .cshtml File with a Accordion Function. Nothing special, just a custom Function so I can render stuff.

@helper Accordion(string text, HtmlHelper html)
{
   <div class="accordion">
       <div><h4>Das ist der Header</h4></div>
       <div>
           <p>Das ist der Content</p>
           <p>@text</p>
           @using(){

           }

       </div>
   </div>
}

In this extra File, you can use the System HtmlHelper (via Html), as well as an Helper you get from a parameter html.

Now when I try to use my custom Extension ie in the Index View I can call

@using(Html.RoleContainer()){}

But in this extra render File, I can't call nor see Html.RoleContainer or html.RoleContainer.

How can I make the RoleContainer available in the extra File so I can use it in my Accordion Function?

Community
  • 1
  • 1
Loki
  • 4,065
  • 4
  • 29
  • 51

1 Answers1

0

After looking into Intellisense, I realized that the Object in Index.cshtml is type HtmlHelper<dynamic>.

What I did is changing my code to

@helper Accordion(string text, System.Web.Mvc.HtmlHelper<dynamic> html)
{
   <div class="accordion">
       <div><h4>Das ist der Header</h4></div>
       <div>
           <p>Das ist der Content</p>
           <p>@text</p>
           @using(html.RoleContainer())
           {
               for(int i = 0; i < 4; i++){
                   <li>
                       @i: Test
                   </li>   
               }
           }

       </div>
   </div>
}

That way I can use the extension RoleContainer as you can see in the code snippet.

@ASP.cshtml.PostHelper.Accordion("Content 1", Html)
Loki
  • 4,065
  • 4
  • 29
  • 51