且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC 3 - 确认问题

更新时间:2023-01-07 08:18:23

这是我发现做到这一点,只需添加simpliest方式数据-VAL - * - * 在属性 HtmlAttributes DropDownListFor 时,视图中。下面的方法与RemoteValidation工作过,如果你不需要远程验证,只需删除包含数据-VAL-远程元素 - *

This is the simpliest way I found to do it, just adding data-val-*-* attributes in HtmlAttributes of DropDownListFor, inside the view. The following method works with RemoteValidation too, if you do not need remote validation, simply remove the elements containing data-val-remote-*:

        @Html.DropDownListFor(m => m.yourlistID, (IEnumerable<SelectListItem>)ViewBag.YourListID, String.Empty, 
        new Dictionary<string, object>() { { "data-val", "true" }, 
        { "data-val-remote-url", "/Validation/yourremoteval" }, 
        { "data-val-remote-type", "POST" }, { "data-val-remote-additionalfield", "youradditionalfieldtovalidate" } })

我希望这可以帮助。顺祝商祺!

I hope it may help. Best Regards!