Helpers

From Logic Wiki
Jump to: navigation, search

Make sure you have the namespace for your extensions class included in your web.config. For example

namespace MyProject.Extensions
{ 
  public static class LinkExtensions
   {
     //code
   }
}

In your site Web.config and/or Web.config located in your "Views" folder

<system.web>
  <pages>
   <namespaces>
     <add namespace="MyProject.Extensions" />
   </namespaces>
  </pages>
</system.web>

otherwise include a "using" block for the namespace at the top of your view page can work but for common namespaces I would do the above.

Razor :

@using MyProject.Extensions

in Code

@using (Html.BeginForm("update", "booking", FormMethod.Post, new{@class = "form-horizontal"}))

If @using is used it puts end tag when curly bracelets closes. So you don’t need

@{ Html.EndForm(); }

Usage of user defined helper

@Html.getMenu(1,1)


and in definition

 public static MvcHtmlString getMenu(this HtmlHelper htmlHelper, int MenuID, int SkinID)
 {
   ……
   return new MvcHtmlString(sb.ToString());
 }



MVC helpers.png

Related Pages :

MVC

MVC_Bundles