嗨我是相當新的MVC3,我試圖做一些我認爲必須相當普遍,但不能完全得到它。ASP.NET MVC3 DropDownListFor枚舉
我有一個模式,我希望存儲枚舉星期幾的值:
public class Booking
{
public int ID { get; set; }
public int Day { get; set; }
....
}
我做了它一個int在數據庫中存儲。
我想在查看一個DropDownList編輯:
<div class="editor-field">
@Html.DropDownListFor(model => model.Booking.Day, new SelectList(Enum.GetValues(typeof(DayOfWeek))))
@Html.ValidationMessageFor(model => model.Booking.Day)
</div>
但是我得到的錯誤:「天域必須是數字」。
我知道我錯過了一些東西,可能是簡單的東西,任何人都可以幫忙嗎?
mode.Booking.Day在代碼中當時的價值是什麼?這是一個數字嗎?或者它是空的?或者是其他東西? –
據我所知,這是枚舉的字符串。即:星期一 –
是不是model.Booking.Day一個int? 「public int Day {get; set;}」 –