我正在尝试使用Data-annotations来验证ajax请求
var request = $.ajax({
url: "http://localhost:55555/WebService1.asmx/HelloWorld",
type: "POST",
data: JSON.stringify({
request: {
Id: '34',
Value: 'Hello World'
}
}),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
服务器端:
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[ScriptService]
public class WebService1 : WebService
{
[WebMethod]
public string HelloWorld(TestClass request)
{
return request.Value;
}
}
public class TestClass
{
[Range(0,10)]
public string Id { get; set; }
[StringLength(2)]
public string Value { get; set; }
}
我希望这会失败,因为我的输入参数与我所需的属性不匹配。但相反它工作正常,我能够用我的&#34;无效&#34;创建课程。参数 我做错了什么?