Reputation: 80
I am getting this error:
"An exception of type 'System.NullReferenceException' occurred in App_Web_lmzivtl2.dll but was not handled in user code. Additional information: Object reference not set to an instance of an object."
And here is the code I was using:
@model IEnumerable<PtExamen.Models.Teste>
@{
ViewBag.Title = "Teste";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Teste</h2>
@{foreach (var item in Model )
{
<p>
  @Html.Raw(ViewBag.Descriere) <br> <br>
    <a href="@ViewBag.NumeFisier" target="_blank">@ViewBag.test</a>)
</p>
}
}
I do not understand why this error came to be since i have used similar examples of this so far and I did not get this problem. Any help, explanation would be great. Thanks in advance!
I used something similar elsewhere and this error did not take place and I cant really find what made this part of the code not cause any problems and the other did. Here is another place I used something similar but I did not have any problems:
@model IEnumerable<PtExamen.Models.Capitole>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
<div id="div-1">
<p><h2> @ViewBag.MateriaSelectata.ToUpper()</h2></p>
</div>
<div id="div-1a">
@foreach (var item in Model)
{
string materiasel = ViewBag.MateriaSelectata;
int cidSelectat = Convert.ToInt32(ViewBag.cidSelectat);
<p>@Html.ActionLink(item.den_capitol, "Index", new { materia = item.disciplina , cid = item.id }) <br></p>
Upvotes: 1
Views: 26165
Reputation: 151
Somewhere in your dll (App_Web_lmzivtl2.dll) you referencing a null object or you forgot to instantiate it. i.e object myobject=new object(); then give myobject a value.
Upvotes: 6