Passing SelectList to Partial View

capri

Active member
Joined
Jun 16, 2015
Messages
42
Programming Experience
5-10
Hi,

I have a model from database, to which I added a property to get the FullName like

C#:
public string FullName
{
      get
      {
           return Firstname + " " + LastName;
       }
}

I then add this code in Controller as follows

C#:
public ActionResult GetList()
{
     SelectList sList = new SelectList { db.Details, "Id", "FullName"};
    
     return PartialView("_test",sList);
}

In _test.cshtml, how do I get this sList through model? Please help

Thanks
 
The Model IS the SelectList. If I gave you a sandwich for lunch, would you have to ask how to get the sandwich from the lunch? The sandwich IS the lunch. Likewise, you're not getting the SelectList from the Model because the Model IS the SelectList. Where you need that SelectList in your view, you use the Model.
 
Back
Top Bottom