0

i have a question from you guys! i decided to create an HmlHelper with some of HtmlHelrs inside of it and I create this Helper in Razor format, but when compiling the project I got an null reference Error which points to HtmlHelpers that I used inside . so i dont know how can i solve this problem

see this View that i created :

 @helper LanguageCheckBoxes(string containerCssClass,string containerSpanCssClass,string checkboxParentCssClass,
    string name, string checkboxCssClass, IEnumerable<System.Web.Mvc.SelectListItem> model)
{
    <div class="@containerCssClass">
    @Html.Label(@BMAIiCGS.Resources.Public.Labels.LanguageList, new { @class = "control-label col-md-3" })
<span class="@containerSpanCssClass">
    @foreach (var item in model)
        {
        <span class="@checkboxParentCssClass">
            <input type="checkbox" name="@name" value="@item.Value" checked="@item.Selected" disabled="@item.Disabled" class="@checkboxCssClass" />
            @Html.Label(item.Text, new { @class = "control-label" })
        </span>

        }
</span>
</div>
}

and this is the Error which i cached :

enter image description here

I appreciate someone helps me

  • You should probably get rid of `@` prefix on `@BMAIiCGS.Resources.Public.Labels.LanguageList`. – Nenad May 14 '15 at 14:28
  • Are you sure "@BMAIiCGS.Resources.Public.Labels.LanguageList" contains data? Also, I cannot say that Html.Label(...) is what you want to use here. @BMAIiCGS.Resources.Public.Labels.LanguageList might work equally well. – Eckert May 14 '15 at 14:28
  • @Eckert : Yup ! i'm sure this value is not Null and also I must add this notation that I used this html block in my main View before and there was Not any Error before.so i think this can not lead to this Error. – Ehsan Shirvan May 14 '15 at 14:35
  • try @BMAIiCGS.Resources.Public.Labels.LanguageList outside of the Label helper. like: @BMAIiCGS.Resources.Public.Labels.LanguageList. Does it still give you an error? – Eckert May 14 '15 at 14:39
  • @Eckert : I did what you said but still i have same error. Note : I searched the web and i found the same problem on this link (ofcourse same error with MVC3 and I'm working on MVC5 ) : http://stackoverflow.com/questions/4710853/using-mvc-htmlhelper-extensions-from-razor-declarative-views – Ehsan Shirvan May 14 '15 at 14:54
  • but this also could NOT help me out – Ehsan Shirvan May 14 '15 at 14:55
  • You should edit your OP and include the helper code. If your helper does return data, it would show something, rather than giving a null exception error. – Eckert May 14 '15 at 15:01
  • @Eckert : Excuse me budy! I didnt get what you mean by OP – Ehsan Shirvan May 14 '15 at 15:17
  • OP = original post (your question post). As in update your question to include your helper code. – Eckert May 14 '15 at 16:00

0 Answers0