Asp.net mvc 如何在MVC中将模型作为下拉列表传递

Asp.net mvc 如何在MVC中将模型作为下拉列表传递,asp.net-mvc,Asp.net Mvc,我是MVC新手,在如何将模型作为下拉列表传递给视图方面遇到了一些问题。我有两个这样的模型 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;s

我是MVC新手,在如何将模型作为下拉列表传递给视图方面遇到了一些问题。我有两个这样的模型

 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>
我需要添加一个fueltype下拉列表,列出数据库中的fueltype。但我不确定如何在这里访问燃料模型

<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>
对于我来说,通过燃料模型在下拉列表中查看和列出结果的最佳方式是什么

谢谢

只需使用DropDownListFor与下拉列表绑定即可

请参阅此处的更多详细信息

可能重复的