user3274859
user3274859

Reputation: 1

show details view in mvc 3

HI i am new to mvc so if anyone can help me will be great basically i just want to display a partiular item details, my code

    private sneakerEntities
       _sneaker_categoryDataModel = new sneaker_info.Models.sneakerEntities();
    public ActionResult Index()
    {
        IList<sneaker> Releases = _sneaker_categoryDataModel.sneakers.ToList<sneaker_info.Models.sneaker>();
        return View("Releases", Releases);

    }

    //
    // GET: /Home/Details/5

    public ActionResult Details (int id)

    {


        return View();

    }

Upvotes: 0

Views: 115

Answers (2)

Rajshekar Reddy
Rajshekar Reddy

Reputation: 18997

     private sneakerEntities
           _sneaker_categoryDataModel = new sneaker_info.Models.sneakerEntities();
        public ActionResult Index()
        {
            IList<sneaker> Releases = _sneaker_categoryDataModel.sneakers.ToList<sneaker_info.Models.sneaker>();

           // populate your IList with values here
            return View("Releases", Releases);

        }

After this Add a View By right clicking on this Action. You will have a view Created which will have the First line as

@model IList<sneaker>

if not change it to this. Now write this syntax to retrieve values from each item of the list

@foreach(var data in Model)
{
   //@data.Whatever
    @data.Name 
}

Upvotes: 0

Murali Murugesan
Murali Murugesan

Reputation: 22619

You need to find it from Repository and display in your strongly typed view

public ActionResult Details (int id)
{

   Sneaker snkr=_sneaker_categoryDataModel.sneakers.Find(id);

   return View(snkr);

}

In Details.cshtml

@model Sneaker 

//all view related code

Upvotes: 1

Related Questions