【发布时间】:2013-12-19 14:58:54
【问题描述】:
这是我的 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
}
这是我在控制器中的创建操作:
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);
}
在我的创建视图中:
<div class="form-group">
@Html.LabelFor(model => model.Condition)
@Html.DropDownListFor(model => model.Condition, ViewBag.DropDownList as SelectList, null)
</div>
我正在使用 Enumhelper,您可以找到 here。
但是现在我总是在我的 Create View 中遇到这个错误:
@Html.DropDownListFor(model => model.Condition, ViewBag.DropDownList as SelectList, null)
错误:
错误 1 以下方法或属性之间的调用不明确:'System.Web.Mvc.Html.SelectExtensions.DropDownListFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections. Generic.IEnumerable,字符串)'和'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
【问题讨论】:
标签: mysql asp.net-mvc asp.net-mvc-4 razor enums