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 6860669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:26:15+00:00 2026-05-27T02:26:15+00:00

I’ve just build my first Helper in MVC, it’s very basic and just displays

  • 0

I’ve just build my first Helper in MVC, it’s very basic and just displays a string where ever I use it. So it’s a .cshtml file in my App_Code folder, I think that is how it’s supposed to be set up, with the following code in it,

@helper DisplaySelect() {
    @:This text is coming from an helper class.
}

Now I am a wiz with helpers how do I make it do things. E.g.. say I want it to query the database and display something, I would normally do that work in my controller. How do I do that with helpers, do I create a helper controller and then treat the helper like a partial view???

Any help would be greatly appreciated.

Cheers,

Mike.


Thanks guys,

I’ve asked that question before Shark “Why would you use a helper and not a partial view” the answer I got there was a partial view is more for just displaying common HTML where as a Helper can have a bunch of code in it and do all kinds of great processing stuff. Now it seems that’s not true and they are pretty much the same thing, in some respect, except in Link664’s case!

I like what you’re saying Link664 that makes sense as it cleans up the code nicely.

What I was going to do was try and populate a drop down list in a helper and then use it in multiple places, but from my research today that’s not what helpers are for.
Cheers,

Mike.

  • 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-05-27T02:26:15+00:00Added an answer on May 27, 2026 at 2:26 am

    I’m a bit confused by what you want to do and why you want to do it but I’ll give it a go. As you mentioned, you would normally do that work in your controller. It is very poor design to make database calls from a partial view/html helper created client-side.

    The @helper syntax is to be used only for simplifying view code, not for implementing code that should be in the controllers or models in the view. See this article for a better idea of when you should be using them.

    As for your example, I recommend you pass the data that you want from your controller and create an extension method on HtmlHelper to render it in your view. For example if you wanted to display a list of the most recent 10 posts on your view:

    public static HtmlString RecentPostsDisplay(this HtmlHelper html, string name,
                                         List<Post> values, object htmlAttributes)
    {
        var tag = new TagBuilder("ul");
    
        ...            
        //build list content by looping through values and adding to TagBuilder
        ...
    
        return new HtmlString(tag.ToString(TagRenderMode.SelfClosing));
    }
    

    and in your controller

    public ActionResult Blah()
    {
        ViewBag.posts = _db.GetMostRecentPosts();
        return View();
    }
    

    Then in your view you can put

    @Html.RecentPostsDisplay(ViewBag.RecentPosts)
    

    Hopefully that is what you are looking for, if not update your question so it’s not so ambiguous and I’ll try again!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to build my first dynamic Website. I want to use PHP,
I've just installed monotouch and having a problem with my first build of an
i'm new to asp.net mvc.. so basically i just build up a two page
I have just started trying to build my first wp7 app, and I am
I have just managed to build my first C extension for Python, using Cython
I've just recently completed my first nightly build script (first significant anything script, really)
We've just set up our first Build Agent with TFS to run unit tests
I have just built up my first SVN server, along with the mod_dav_svn module
Just updated build server with rc0 and surprise no chiron. Wondering how you package
This build warning just started showing up. I'm building for 3.1.3. Not sure what

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.