Model validation depth will
add validation manual error
view which shows validation error messages for each property
to display the entire model-level errors
Custom validation
If you need more complex business logic validation. And the validation logic can be multiplexed everywhere, then you should consider using a custom Attribute
because the type DataType using the Url
to the original default comes with the verification url attribute removed, wrote a validation url of the
new folder. And a new class
first need to put an attribute error message
context is a context model verification
and validation url. Context.model is our property to validate
that we know we have to verify that string, so to turn into a string of
test
Attribute function description of the custom
Remote Authentication
第一个参数是Aciton 的名字,第二个参数是Controller的名字
然后在RoleController里面添加Action
既接收get请求也接收post请求
再看View,有一个RoleName
使用Bind绑定到这里
随便写一个角色,没点提交按钮。 会自动提交到后台
后台就会到断点这里
写一个已经存在的角色就会提示存在了
返回的信息如果是false是什么效果呢?
错误信息是在ViewModel里面定义的
第一个参数是Action的名字 这么写有利于重构
如果后面的Controller也用nameof的形式,就会报错了
所以第二个参数只能写字符串