2
@model MvcDemo.Models.MovieDB

<fieldset>
    <legend>MovieDB</legend>

    <div class="display-label">Title</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Title)
    </div>

    <div class="display-label">Director</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Director)
    </div>

    <div class="display-label">Date</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Date)
    </div>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id=Model.ID }) 
    @Html.ActionLink("Back to List", "Index")
</p>

When I am executing this , an error message is coming which is as follows ... System.NullReferenceException: Object reference not set to an instance of an object. The error is occuring at the 2nd last line i.e.@Html.ActionLink("Edit", "Edit", new { id=Model.ID })

Craig W.
  • 17,838
  • 6
  • 49
  • 82
Kiran Dey
  • 21
  • 1

1 Answers1

0

In your action method, just before you return the ActionResult have a look at the model and confirm that the ID property is populated - I think you'll find it isn't.

If your action method is a HTTP Post, does the view that has been submitted contain a control for the ID field? If not, try using a "Hidden" input field - the HiddenFor(...) method will help you out with it...

Martin Milan
  • 6,346
  • 2
  • 32
  • 44
  • Also, do you really have a controller called Edit? That's a little strange - usually you'll have a controller for each type of entity you are working with, and the Add / Delete / View / Update / List methods etc would be Action methods on that controller... – Martin Milan Oct 21 '14 at 16:25