我无法理解我的问题所在。
我有一个型号"车辆"它有两个属性是Enum&
在我的视图中,我正在尝试使用Html.EnumDropDownListFor
。
我的模特是这样的:
public class VehicleModels
{
[Key]
public virtual int Id { get; set; }
public virtual string Naam { get; set; }
public virtual Merken Merk { get; set; }
public virtual Brandstoffen Brandstof { get; set; }
public virtual string Kleur { get; set; }
public virtual string TypeVanMerk { get; set; }
public virtual string TypeVanTransmissie { get; set; }
public virtual int Kilometerstand { get; set; }
public virtual int Bouwjaar { get; set; }
public virtual int AantalDeuren { get; set; }
public virtual int Prijs { get; set; }
public virtual ICollection<Optie> Options { get; set; }
public virtual ICollection<Foto> Fotos { get; set; }
public VehicleModels()
{
}
}
My Enum's:
public virtual Merken Merk { get; set; }
public virtual Brandstoffen Brandstof { get; set; }
-
public enum Merken
{
[Display(Name="Alfa Romeo")]
AlfaRomeo,
Audi,
Bentley,
BMW,
Chevrolet,
Citroën,
Chrystler,
Dacia,
Fiat,
Ford,
Honda,
Hyundai,
Kia,
Lexus,
Mazda,
Mercedes,
Mitsubishi,
Nissan,
Opel,
Peugot,
Renault = 20,
Seat,
Skoda,
Toyata,
Volkswagen,
Volvo,
[Display(Name ="Overige merken")]
Overige
}
在我的视图中我有这个:
@model IEnumerable<Cvo.Eindwerk.KevinVanKerrebroeck.Models.VehicleModels>
@{
ViewBag.Title = "Index";
}
<div id="filterbar">
<div class="filterBarComponent">
<div class="dropdownContainer">
@Html.DropDownList("Merk", new SelectList(Enum.GetValues(typeof(Merken))), "--Kies Merk")
</div>
<div class="dropdownContainer">
@Html.DropDownList("Brandstof", new SelectList(Enum.GetValues(typeof(Brandstoffen))), "--Kies Brandstof")
</div>
</div>
<div class="filterBarComponent">
<div>
<label for="sliderPrijs">Maximum Prijs</label>
<input id="sliderPrijs" type="range"
min="100" max="50000"
step="100" value="25000"
oninput="outputUpdatePrijs(value)">
<output for="sliderPrijs" id="prijs">25000</output>
</div>
<div>
<label for="sliderKm">Kilometer Stand</label>
<input id="sliderKm" type="range"
min="0" max="500000"
step="10000" value="500000"
oninput="outputUpdateKilometers(value)">
<output for="SliderKm" id="kmStand">500000</output>
</div>
</div>
但我想使用@Html.EnumDropDownListFor(model => model.Merk , "--Kies merk")
但似乎我的View无法识别我的模型的属性。
Intellisense没有显示任何属性,当我输入它时我得到错误:
CS1061:&#39; IEnumerable&lt; VehicleModels&gt;&#39;不包含&#39; Opties&#39;的定义没有延伸方法&#39; Opties&#39;接受类型&#39; IEnumerable&lt; VehicleModels&gt;&#39;的第一个参数。可以找到(你错过了使用指令或程序集引用吗?)
然而,在详细信息视图中,我能够做到这一点,它显示出我想象的那样。
我的详细信息视图:
@model Cvo.Eindwerk.KevinVanKerrebroeck.Models.VehicleModels
@{
ViewBag.Title = "Details";
}
<div id="detailsPage">
@Html.EnumDropDownListFor(model => model.Merk)
<h2 id="detailsTitle">Details voor @Model.Merk @Model.TypeVanMerk</h2>
<hr />
<dl class="dl-horizontal">
为什么这在我的详细信息视图中工作,而不在我的索引视图中?