mvc中使用remote属性来做ajax验证

前端之家收集整理的这篇文章主要介绍了mvc中使用remote属性来做ajax验证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
mvc中使用remote属性来做ajax验证比较容易 :


  [Remote("Action","Controller",AdditionalFields = "Currency")]
public decimal Amount {get; set;}



生成HTML:


<input class="form-control" data-val="true" data-val-number="字段金额必须为数字" data-val-range="取款金额范围在100.00和10000.00之间。" data-val-range-max="10000.00" data-val-range-min="100.00" data-val-remote="'金额' is invalid." data-val-remote-additionalfields="*.Amount,*.Currency" data-val-remote-url="/XXX/YYY" data-val-required="请输入金额。" id="Amount" name="Amount" type="text" value="0">




也可以直接在view中写,razor在render页面时候会相应生成data-val-remote-开头的属性


 @Html.TextBoxFor(i => i.Amount,new
                        {
                            @class = "form-control",data_val_remote_additionalfields = "*.Amount,*.Currency",data_val_remote_url = Url.Action("Action","Controller"),})
原文链接:https://www.f2er.com/ajax/164159.html

猜你在找的Ajax相关文章