How do I code a MVC3 Helper

Posted by Mike Clarke on Stack Overflow See other posts from Stack Overflow or by Mike Clarke
Published on 2011-11-29T01:48:11Z Indexed on 2011/11/29 1:49 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about database

Related posts about asp.net-mvc-3