mvc中使用remote属性来做ajax验证
发布时间:2020-12-16 00:16:24 所属栏目:百科 来源:网络整理
导读: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-r
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"),}) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |