2012-03-09 84 views
1

我有以下的下降asp.net的MVC定下ASP.net MVC驗證問題

@Html.DropDownListFor(model => model.DataId, ((IEnumerable<ProgrammeModel>)ViewBag.Data).Select(option => new SelectListItem 
     { 
      Text = (option == null ? "None" : option.Name), 
      Value = option.DataId.ToString(), 
      Selected = (Model != null) && (option.DataId== Model.DataId) 
     }), "Choose...", new { Class = "input", id = "DataId" 

    }) 

,並在型號:

[Required(ErrorMessage="The Data field is required.")] 
public int DataId { get; set; } 

但是,當驗證發生在表單提交我是獲取此字段的錯誤消息爲

Int32字段是必需的。

在那裏我期待的結果作爲

數據字段需要

你能幫我嗎?

感謝, Ajai

回答

0

我有同樣的問題,這似乎在控制你有ViewBag.DataId,它是造成混亂的驗證。 請嘗試刪除它,讓我知道如果它現在可以。

感謝, 貝爾巴托夫

1
@Html.DropDownListFor(model => model.DataId, 
         new SelectList(ViewBag.Data as System.Collections.IEnumerable, 
         "DataId", "Name"), "Choose") 
+0

不,它仍然沒有工作 – 2012-03-12 11:20:25

+0

什麼是確切的錯誤,現在 – DKD 2012-03-13 06:26:36