This is my ViewModel:
public class EntityViewModel
{
[Required(ErrorMessage = "Title is required")]
[StringLength(255)]
[DisplayName("Title")]
public string Title { get; set; }
[Required(ErrorMessage = "Description is required")]
[DisplayName("Description")]
public string Description { get; set; }
[Required]
public DateTime StartTime { get; set; }
[Required]
public DateTime EndTime { get; set; }
[Required]
public Decimal InstantSellingPrice { get; set; }
public Nullable<Decimal> ShippingPrice { get; set; }
public Int64 Views { get; set; }
public Int32 UserId { get; set; }
public int RegionId { get; set; }
public short SelectCategoryId { get; set; }
public SelectList Categories { get; set; }
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public Condition? Condition { get; set; }
}
public enum Condition
{
New=1,
Used=2
}
This is my Create Action in my Controller:
public ActionResult Create()
{
ViewBag.DropDownList = ReUzze.Helpers.EnumHelper.SelectListFor<Condition>();
var model = new ReUzze.Models.EntityViewModel
{
Categories = new SelectList(this.UnitOfWork.CategoryRepository.Get(), "Id", "Name")
};
return View(model);
}
In my Create View:
<div class="form-group">
@Html.LabelFor(model => model.Condition)
@Html.DropDownListFor(model => model.Condition, ViewBag.DropDownList as SelectList, null)
</div>
I am using the Enumhelper that you can find here.
But now I always get this error in my Create View on this rule:
@Html.DropDownListFor(model => model.Condition, ViewBag.DropDownList as SelectList, null)
The error:
Error 1 The call is ambiguous between the following methods or properties: 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IEnumerable, string)' and 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IEnumerable, System.Collections.Generic.IDictionary)' c:\Users\Niels\Documents\Visual Studio 2012\Projects\ReUzze\ReUzze\Views\Entity\Create.cshtml 57 30 ReUzze