Results 1 to 2 of 2

Thread: Passing SelectList to Partial View

  1. #1
    capri is offline C# Forum Enthusiast
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2015
    Posts
    31
    Rep Power
    25

    Passing SelectList to Partial View

    Hi,

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

    Code:
    public string FullName
    {
          get
          {
               return Firstname + " " + LastName;
           }
    }
    I then add this code in Controller as follows

    Code:
    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

  2. #2
    jmcilhinney is offline C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •