title: Consuming a Helper code for optgroup functionality in Asp.net MVC
body: <p>I don't have the experience of working with Helpers so I am bit stuck in using a code at hand. </p>
  
  <p>My requirement is simple and all I need is optgroup functionality in <code>DropDownListFor</code> extension method. While searching, I came across this <a href="https://stackoverflow.com/a/4248856/570928">Answer</a> and have copied this as it is in a file named <em>MyExtensionClass.cs</em>.</p>
  
  <p>But, I don't know how to use this or call the extension method defined in this. Please tell me how can i use this with my list. </p>
  
  <p>Right now, following is the controller code for a selectlist for which i want to use the extension methods.</p>
  
  <pre><code>ViewBag.ParentCategoryId = new SelectList(db.Categories, "Id", "Name");
  </code></pre>
  
  <p>And this is my view code </p>
  
  <pre><code>@Html.DropDownListFor(model =&gt; model.Product.CategoryId, 
       (IEnumerable&lt;SelectListItem&gt;)ViewBag.CategoryId, "---Choose Category---", 
         new { @class = "required" })  
  </code></pre>
  
  <p>Please help me upgrade this to extension method with optgroup.</p>