Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:32:05+00:00 2026-06-18T15:32:05+00:00

In a previous post I asked a question about getting started with helpers. I

  • 0

In a previous post I asked a question about getting started with helpers. I was successful but when I tried to use the technique 1. To write a different helper based on Html.RenderAction, and 2. To pass in my own custom helper I got errors once they were exported to App_Code.

Again, to emphasise, they work inline, but not when exported to App_Code.

Here is the original code:

Many parts of my code have only the following:

    <section class="Box">
        @{ Html.RenderAction("PageOne"); }
    </section>

Many other parts have this:

@if (@Model.PageTwo)
{
    <section class="Box">
        @{ Html.RenderAction("PageTwo"); }
    </section>
}

So my first step was to extract out into an inline helper the following which could be used in all of my code blocks above:

@helper Item(HtmlHelper html, string action, string htmlClass)
{
    <section class="@htmlClass">
        @{ html.RenderAction(action); }
    </section>
}

The helper above allows me to replace all the code blocks that look like the first code segment above with this line:

@Item(Html, "PageOne", "Box")

Then I went on to write the second helper which looks like this:

@helper Item(HtmlHelper html, string action, string htmlClass, bool test)
{
    if (test)
    {
        @Item(html, action, htmlClass)
    }
}

This helper allows me to replace all the code blocks that look like the second code segment above with this line:

@Item(Html, "PageTwo", "Box", @Model.ShowThisTorF)

My main question once again is, this works inline, so why not when I remove it to App_Code.

Once I move it to App_Code I get the following errors:
The first problem is regarding adding a using reference (because HtmlHelper is ambiguous) to which I add the following line of code:

 @using HtmlHelper=System.Web.Mvc.HtmlHelper

This removes the first error but then I get another error:

System.Web.Mvc.HtmlHelper does not contain a definition for
‘RenderAction’ and no extension method ‘RenderAction’ accepting a
first argument of type ‘System.Web.Mvc.HtmlHelper’ could be found (are
you missing a using directive or an assembly reference?)

I have also tried the other reference but with no result:

 @using HtmlHelper=System.Web.WebPages.Html.HtmlHelper

Another problem that I am having is that I don’t think the second block will work once I get the first one working. Even though it worked fine inline.

Also, I know its obvious, but if I don’t say it here, someone will ask it in their answer. When I moved it out to the file App_Code, I did indeed add the file name prefix as required so the one line lumps of code looked something like:

@Helpers.Item(Html, "PageOne", "Box")
@Helpers.Item(Html, "PageTwo", "Box", @Model.ShowThisTorF)

Thanks for any help with this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:32:06+00:00Added an answer on June 18, 2026 at 3:32 pm

    The correct HtmlHelper inside helpers in the App_Code directory is the System.Web.Mvc.HtmlHelper.

    Because RenderAction is an extension method you need to add a using for the namespace where it is declared which is @using System.Web.Mvc.Html

    So this should work assuming your file is named Helpers.cshtml and in the App_Code directory:

    @using HtmlHelper=System.Web.Mvc.HtmlHelper
    @using System.Web.Mvc.Html
    
    @helper Item(HtmlHelper html, string action, string htmlClass)
    {
        <section class="@htmlClass">
            @{ html.RenderAction(action); }
        </section>
    }
    @helper Item(HtmlHelper html, string action, string htmlClass, bool test)
    {
        if (test)
        {
            @Item(html, action, htmlClass)
        }
    }
    

    And the usage:

    @Helpers.Item(Html, "PageOne", "Box")
    @Helpers.Item(Html, "PageTwo", "Box", @Model.ShowThisTorF)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please refer my previous post here . I did changes accordingly but getting error.
A previous question, Multiple directories and/or subdirectories in IPython Notebook session, asked about directory
I've made a previous post that tried to use a textbox. From this I
So in a previous question I asked about whats the most RESTful way to
Hello guys I think the question i asked in the previous post is unclear
I asked this question earlier and thought it was fixed, but it's not. Previous
Possible Duplicate: What does ||= mean? In this previous question, I asked about an
I looked at previous post based on this but they do not relate. I
This post if a follow-up question to mt previous post: Android RESTful Web application
I know this question's been asked a couple times before, but none of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.