Remote ViewModel validation of nested objects not working

后端 未结 3 870
北恋
北恋 2020-12-31 13:02

I have a class user which looks like this:

public class User
{
    public int UserId { get; set; }

    [Required(ErrorMessage = \"A username is required.\")         


        
3条回答
  •  清歌不尽
    2020-12-31 14:00

    For the remote validation part nothing jumps out at me. It might be helpful to open up firebug and see what the request that is being fired looks like. You should see something roughly like this if everything is properly wired up...

    http://localhost:14547/[Controller]/[ActionName]?[ParamName]=[paramValue]

    From the request you provided, you can either use a prefix like you ended up doing or you can make your action take a user named UserToRegister and then within the action access the UserName property. This is the recommended way of dealing with remote validation of objects and might be a little easier to think about than using a Bind attribute.

    For the compare validation, it appears that on the client side validation is succeeding but on the server side validation fails because the validation context does not contain a property named User.Password, only a property named User.

提交回复
热议问题