大佬教程收集整理的这篇文章主要介绍了asp.net-mvc – MVC数据注释范围验证无法正常工作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
模型:
public class Mymodel { ... [required(Errormessage = "{0} is required")] [Range(typeof(int),"0","100",Errormessage = "{0} can only be between {1} and {2}")] public int Percentage { get; set; } ... }
部分视图:
@model MyApp.Models.Partials.Mymodel <div id="myDialog" class="editModal" title="update Percentage"> @using (Ajax.beginForm("updatePercentage","MyController",new AjaxOptions() { httpR_858_11845@ethod = "Post",Onsuccess = "onupdatesuccess" },new { name = "myForm" })) { @Html.ValidationSumMary(null,new { style = "width:auto;max-width:22em; float:left;clear:both;" }) <div style="width:auto;float:left;clear:both;"> <div style="width:10em;float: left;text-align:right;clear:left;"> @Html.Label("Percentage:") </div> <div style="width:12em;margin-left:1em;float:left;clear:right;"> @Html.TextBoxFor(m => m.PercentagE) </div> </div> <div style="width:23em;clear:both;text-align:center;"> <hr /> <input type="button" value="Cancel" class="cancelModalButton" data-modal="myDialog" /> <input type="submit" value="Submit" class="submitModalButton" data-modal="myDialog" data-form="myForm" /> </div> } </div>
标记产生:
<div id="myDialog" class="editModal" title="update Percentage"> <form action="/Web/MyController/updatePercentage?Length=3" data-ajax="true" data-ajax-method="Post" data-ajax-success="onupdatesuccess" id="form2" method="post" name="myForm"> <div class="validation-sumMary-valid" data-valmsg-sumMary="true" style="width:auto;max-width:22em;float:left;clear:both;"> <ul> <li style="display:none"></li> </ul> </div> <div style="width:auto;float:left;clear:both;margin-bottom:.75em;"> <div style="width:10em;float: left;text-align:right;clear:left;"> <label for="Percentage:">Percentage:</label> </div> <div style="width:12em;margin-left:1em;float:left;clear:right;"> <input data-val="true" data-val-number="The field Percentage must be a number." data-val-range="Percentage can only be between 0 and 100" data-val-range-max="100" data-val-range-min="0" data-val-required="Percentage is required" id="Percentage" name="Percentage" type="text" value="10" /> </div> </div> <div style="width:23em;clear:both;text-align:center;"> <hr /> <input type="button" value="Cancel" class="cancelModalButton" data-modal="myDialog" /> <input type="submit" value="Submit" class="submitModalButton" data-modal="myDialog" data-form="myForm" /> </div> </form> </div>
我看到该类型设置为文本,如果我将我的TextBoxFor更改为编辑器它的数字,但我仍然看到相同的行为。
以上是大佬教程为你收集整理的asp.net-mvc – MVC数据注释范围验证无法正常工作全部内容,希望文章能够帮你解决asp.net-mvc – MVC数据注释范围验证无法正常工作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。