I don't have the experience of working with Helpers so I am bit stuck in using a code at hand.
My requirement is simple and all I need is optgroup functionality in DropDownListFor
extension method. While searching, I came across this Answer and have copied this as it is in a file named MyExtensionClass.cs.
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.
Right now, following is the controller code for a selectlist for which i want to use the extension methods.
ViewBag.ParentCategoryId = new SelectList(db.Categories, "Id", "Name");
And this is my view code
@Html.DropDownListFor(model => model.Product.CategoryId,
(IEnumerable<SelectListItem>)ViewBag.CategoryId, "---Choose Category---",
new { @class = "required" })
Please help me upgrade this to extension method with optgroup.