日期:2014-05-17  浏览次数:20451 次

@Html.DropDownListFor 怎么在客户端验证
@Html.TextBoxFor(a => a.Title, new { style = "width:80%", maxlength = "80" })
可以实现在客户端验证

为什么 @Html.DropDownListFor( a => a.TypeId,(SelectList) ViewData["TypeId"],"—传达范围—")不行?


            <tr>
                <td width="15%">
                    标题:
                </td>
                <td colspan="3">@Html.TextBoxFor(a => a.Title, new { style = "width:80%", maxlength = "80" })
                    @Html.ValidationMessageFor(a => a.Title)
                </td>
            </tr>
            <tr>
                <td width="15%">
                    分类:
                </td>
                <td width="35%">
                    @Html.DropDownListFor( a => a.TypeId,(SelectList) ViewData["TypeId"],"—传达范围—")
                    @Html.ValidationMessageFor(a => a.TypeId)
                </td>
            </tr>




    [MetadataType(typeof(TaskMD))]
    public partial class Task
    {

 
    }
    public class TaskMD
    {
        [Required(ErrorMessage = "必须选择类型")]
        public int TypeId { get; set; }

        [Required(ErrorMessage = "必须设置【任务名称】")]
        public string Title { get; set; }
    }