I am beginner in .NET and I am learning MVC pattern. I am building a demo application which demonstrate CRUD Operations on any product. Before I use any database connectivity, I decided to test it with in memory variable. My code is as below:
Model Class
public class Product
{
[Key]
public int Id { get; set; }
[Required]
[Display(Name="Name")]
public String ProductName { get; set; }
[Required]
[Display(Name="Price")]
public float Price { get; set; }
[Display(Name="Discription")]
public String ProductDiscription { get; set; }
}
Controller Class
public class ProductController : Controller
{
//
// GET: /Product/
public ActionResult Index()
{
return View(new Product{Id = 01, Price=100, ProductName="MyProduct", ProductDiscription="30 TeaBags in a pack"});
}
}
View
@model CrudAppDemo.Models.Product
@{
ViewBag.Title = "Products";
}
<h2>Products</h2>
<div class="row">
<div class="col-md-4 ">
<table class="table">
<thead>
<tr>
<td>@Html.DisplayNameFor(model => model.Name)</td>
<td>@Html.DisplayNameFor(model => model.Price)</td>
<td>@Html.DisplayNameFor(model => model.Description)</td>
</tr>
</thead>
<tbody>
<tr>
<td>@Html.DisplayFor(model => model.Name)</td>
<td>@Html.DisplayFor(model => model.Price)</td>
<td>@Html.DisplayFor(model => model.Description)</td>
</tr>
</tbody>
</table>
</div>
</div>
When I am running this code, I am getting CS0411 Error:
