It is working with ViewData
and ViewBag
but try to strongly type model binding that unable to build Model type reference
What I am missing anyone and doing anything wrong.
View:
@model Working_with_Views.Models.Product;
@{
var product = Model;
}
<h3>Name: @product.Title</h3>
<h2>Price: @product.Price</h2>
<h5>Produce Date: @product.ProduceDate</h5>
view page compile time error
Model:
namespace Working_with_Views.Models
{
public class Product
{
public int ProductId { get; set; }
public string ImgePath { get; set; }
public string Title { get; set; }
public DateTime ProduceDate { get; set; }
public DateTime LeftDateExpire { get; set; }
public decimal Price { get; set; }
}
}
Controller:
public ActionResult Index()
{
Product product = new Product()
{
Title = "Pepsi",
Price = 30.00m,
ProduceDate = DateTime.Now,
LeftDateExpire = DateTime.Now.AddDays(7),
};
return View(product);
}