I m working with asp.net with MVC code-first approaches.
I m learning MVC
first, I create a
- database and
- then create model class and then
- context class
- controller method
record successfully created in the database but I want to get detail of the record but get an error object reference not set to an object
when I click details then give an error object reference not set to an object??
ContextStudent.cs //context class
using System.Data.Entity;
namespace MvcPracTech
{
public class ContextStudent:DbContext
{
public ContextStudent():base("conn")
{
}
public DbSet<students> stud { get; set; }
}
HomeController.cs
[HttpGet] //reload the page and get data
public ActionResult create()
{
return View();
}
[HttpPost] //send the data to second action method
public ActionResult create(students stud)
{
context.stud.Add(stud);
context.SaveChanges();
return View();
}
[HttpGet] //here i m write get method because i want to get the data
public ActionResult Details(int id)
{
var details = context.stud.Find(id);
return View();
}
details.cshtml
Details view:
<h2>Details</h2>
<div>
<h4>students</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.name)
</dt>
<dd>
@Html.DisplayFor(model => model.name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.address)
</dt>
<dd>
@Html.DisplayFor(model => model.address)
</dd>
</dl>
</div>
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.id }) | //here get error object referance not set an objectws
@Html.ActionLink("Back to List", "Index")
</p>
please, help??
what I m missing in above programme??