What is "Helper" in Asp.Net MVC? [duplicate]

6

Please explain to serve Helper in Asp.Net MVC.

I see many examples that contain Helper . I have no idea what Helper is.

And how to create Helper?

    
asked by anonymous 03.05.2017 / 05:07

1 answer

5
  

Please explain to serve Helper in Asp.Net MVC.

Helper is a static class, outside of the Controllers group, which has replicable logic for the rest of the system.

>

By "replicable logic", it is any logic that is used in two or more places in the system. There are several examples here on the site .

Some examples of common Helpers :

  • Consumption and processing of web services ;
  • Creating Word, Excel, etc files
  • Generating links in Views Razor ( HtmlHelper ", UrlHelper ).
  

And how to create Helper?

Basically, as a common static class, in a namespace itself for this. For example:

namespace MeuProjeto.Helpers
{
    public static class MeuHelper
    {
        public static String MetodoDoHelper1() { ... }
        public static int MetodoDoHelper2() { ... }
        public static void MetodoDoHelper3() { ... }
    }
}

Usage:

var retornoString = MeuHelper.MetodoDoHelper1();
var retornoInt = MeuHelper.MetodoDoHelper2();
MeuHelper.MetodoDoHelper3(); // pode não retornar valor, se for o caso.
    
03.05.2017 / 05:16