首页 新闻 赞助 找找看

@Html.DropDownList 和 DropDownListFor JS验证问题

0
悬赏园豆:10 [待解决问题]

controller 代码

 ViewBag.ProductId = new SelectList(productRepository.Queryable(), "Id", "Name", orderdetail.ProductId);

View 代码

<div class="form-group">
@Html.LabelFor(model => model.ProductId, "ProductId", htmlAttributes: new { @class = "control-label col-md-2"})
<div class="col-md-10">
@Html.DropDownList("ProductId", null, "--Select--", htmlAttributes: new { @class = "form-control", val = true })

@*@Html.DropDownListFor(model => model.ProductId, ViewBag.ProductId as IEnumerable<SelectListItem>, "Select One",new { @class = "form-control" })*@
@Html.ValidationMessageFor(model => model.ProductId, "", new { @class = "text-danger" })
</div>
</div>

 

如果我使用 

@Html.DropDownList 输出,可以在编辑状态下选中当前的值,但是JS client 验证无效
@Html.DropDownListFor 输出,JS Client验证有效,但无法选中编辑的值

我想既能选中编辑的值有能触发客户端JS验证要怎么做
 
阿新的主页 阿新 | 初学一级 | 园豆:84
提问于:2015-03-06 12:21
< >
分享
所有回答(1)
0

你要这样的话,你就把这个后面的Html.ValidationMessageFor这个自带的验证去掉,然后用js实现你想要的

_Vegetables | 园豆:586 (小虾三级) | 2015-03-06 14:15

自带验证功能非常强,必须要,因为所有的验证我都在entity的字段上做的

支持(0) 反对(0) 阿新 | 园豆:84 (初学一级) | 2015-03-06 15:09

@阿新: 我的意思是你只把这一个相关的Html.ValidationMessageFor验证去掉,你的目的并不是这一个对吧,你用js或者jQuery验证的时候取他们的ID不是照样可以么,你可以做任意的特效。

支持(0) 反对(0) _Vegetables | 园豆:586 (小虾三级) | 2015-03-09 09:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册