0

I'm new to MVC and i'm having issues on how i can pass a model to a view as a dropdownlist. I have two models like this...

 public class CarModel
    {
       public int Id {get set;}
       public string Manufacturer {get;set;}

    } 


 public class Fuel
    {
     public int Id {get;set;}
     public string FuelType {get;set;}
    }



public ActionResult()
{
   //some logic here
   return View("Home", carModel)
}

And here is the view ..


 @model myproject.Models.CarModel
        <div class="row">
            <div class="col-md-3">
                @Html.LabelFor(m => m.Manufacturer)
            </div>

            <div class="col-md-9">
                @Html.EditorFor(m => m.Manufacturer)
            </div>
        </div>

I need to add a fueltype dropdownlist listing the fueltypes from the database. But i'm unsure on how i can access the Fuel Model here ...

<div class="row">
        <div class="col-md-3">
            @Html.LabelFor(m => m.FuelType)
        </div>
        <div class="col-md-9">
            @Html.DropDownListFor(m => m.FuelType )
        </div>

    </div>

What will be the best way for me to pass the Fuel Model to view and list the results in a dropdownlist?

Thank you

1future
  • 255
  • 5
  • 21
  • Possible duplicate of [ASP.NET MVC - View with multiple models](http://stackoverflow.com/questions/944334/asp-net-mvc-view-with-multiple-models) – Krishna May 04 '17 at 10:00

1 Answers1

1

Simply use DropDownListFor for binding list with drop down.

See more details here

DropDownList in MVC 4 with Razor

Community
  • 1
  • 1
Deepak
  • 1,510
  • 1
  • 14
  • 27