-1
@using SchoolDataLayer
@model SchoolDataLayer.Pupil

@{
    ViewBag.Title = "Pupil";
}

<h2>Schülerdetails</h2>

<fieldset id="details">
    <legend>Schülerdaten</legend>
    <label>Katalognr</label>
    <output>@Model.CatalogNo</output>
    <br />
    <label>Nachname</label>
    <output class="bold">@Model.Lastname</output>
    <br />
    <label>Vorname</label>
    <output>@Model.Firstname</output>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id=Model.PupilId }) |
    @Html.ActionLink("Back to List", "Index")
</p>

The exception occurs in the Line with "@Model.CatalogNo". I have no idea how to go on. Anyone knows whats the problem?

tereško
  • 58,060
  • 25
  • 98
  • 150
max.mustermann1
  • 61
  • 1
  • 2
  • 12
  • Check that your model has been set as it is probably `null` – David Pilkington Mar 09 '14 at 15:26
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Mar 09 '14 at 23:48

2 Answers2

0

I think you need to check your controller is returning your model correctly.

I think that the model property SchoolDataLayer.Pupil.CatalogNo is not holding any data. Therefore there maybe an issue with the data being returned from the db context. Also check that SchoolDataLayer.Pupil is being populated with data properly.

Try putting a watch on SchoolDataLayer.Pupil before the view is returned to see if it holds information.

HTH

Regards

TonySB
  • 13
  • 4
0

Comment out the @Model.CatalogNo and see if the @Model.Lastname is returned OK. If it is then just go back and see what you are doing differently when setting the Lastname and CatalogNo variables.