MVC3 .net 用于 RenderAction 的不显眼的 Javascript
我有一个视图,使用以下方式呈现 3 个部分视图 @Html.Partial 另一个视图使用: @Html.RenderAction 因为这个部分视图需要与其他部分视图不同的模型,所以
我的服务器端验证工作正常,但我无法让客户端验证工作。 我有一个必需的字段,但是,当我将其空白并移动到 renderAction 视图上的下一个字段时,验证不会触发(没有红色背景 - 未设置验证类)。 该字段在底层 ViewModel 中设置为必需。 我将脚本包含在 renderAction 视图中:
<script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"
type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")"
type="text/javascript"></script>
字段的标签按照预期设置为不显眼的 javascript:
<input id="user_Surname" class="names" type="text" value="gggg" title="Must be between 1 and 100 chars in length" name="user.Surname" data-val-required="Surname is required" data-val-length-max="50" data-val-length="Surname length must be between 0 and 50" data-val="true">
我尝试将以下内容添加到 RenderAction 部分视图的末尾:
<script type="text/javascript">
jQuery.validator.unobtrusive.parse();
</script>
但这没有帮助...... 不确定它有什么区别,但这些字段都在 Ajax.BeginForm 中,
提前致谢......
I have a view that renders a 3 Partial views using
@Html.Partial
and another view using:
@Html.RenderAction as this partial view requires a different model to that of the other partials
I have the Server side validation working fine, but I can't get the client validation to work.
I have a field which is required, however, when I blank this out and move to the next field on the renderAction view, the validation is not firing (no red background - validation class not being set).
The field is set to Required in the underlying ViewModel.
I include the scripts in the renderAction View:
<script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"
type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")"
type="text/javascript"></script>
The tags for the fields are being set for unobtrusive javascript as expected:
<input id="user_Surname" class="names" type="text" value="gggg" title="Must be between 1 and 100 chars in length" name="user.Surname" data-val-required="Surname is required" data-val-length-max="50" data-val-length="Surname length must be between 0 and 50" data-val="true">
I've tried adding the following to the end of the RenderAction Partial View:
<script type="text/javascript">
jQuery.validator.unobtrusive.parse();
</script>
But this doesn't help....
Not sure it makes any difference but the fields are all within an Ajax.BeginForm
Thanks in advance.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论