在 Razor 视图中启用客户端验证 (ASP MVC 3) [英] Enable client validation in Razor views (ASP MVC 3)

查看:22
本文介绍了在 Razor 视图中启用客户端验证 (ASP MVC 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用这行代码添加客户端验证:

I try to add client side validation using this line of code:

@Html.EnableClientValidation()

但我不断收到此错误消息:

But I keep getting this error message:

编译器错误消息:CS1502:Microsoft.WebPages.WebPageUltimateBase.Write(Microsoft.WebPages.Helpers.HelperResult)"的最佳重载方法匹配有一些无效参数

这对其他人有用吗,还是 ASP MVC 3 中的另一种方法?

Is this working for anyone else, or is it another approach for this in ASP MVC 3?

推荐答案

您可以改为使用以下内容代替预期的代码行.

You can, instead, use the following in place of the expected line of code.

@(ViewContext.ClientValidationEnabled = true)

可能是对 htmlhelper 扩展方法的疏忽.

Probably an oversight in the extension methods for htmlhelper.

其实可以通过如下操作来使用HtmlHelper方法

Actually, you can use the HtmlHelper method by doing the following

@{ Html.EnableClientValidation(); }

这篇关于在 Razor 视图中启用客户端验证 (ASP MVC 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆