1

The jquery remote validation is adding the prefix of the input field name (mymodel.field1) to each additional field listed in data-val-remote-additionalfields. In my additional fields I have a hidden field that is not part of the model so it has a normal name like "fieldhidden" instead of "mymodel.fieldhidden".

I have confirmed this by reviewing the request object at the controller and verified that one of the query string keys is "mymodel.fieldhidden" instead of "fieldhidden" and the data is null. Pretty sure its null because jquery validation is looking for "mymodel.fieldhidden" and of course can't find it.

Is there a way to make jquery, through mvc attributes, not auto prefix or through jquery manipulation to not auto prefix the additional fields where the name attribute has a value formatted like "model.fieldname" where remote validation is added ?

    [Remote("ValidationMethod", "Controller", AdditionalFields = "FieldNameInModel, ElementNameNotInModel")]
    public string FieldToRemoteValidate { get; set; }
2
  • can you add your model code where you add the remote validation? Commented Jul 27, 2014 at 0:33
  • I added the field in question, thanks! Commented Jul 27, 2014 at 15:23

1 Answer 1

2

What I ended up having to do was add the hidden field twice. I already had a generic setup for multiple actions in the controller expecting the name as was. So by adding the hidden field with the naming convention that the jquery validation library expected, it was then transmitted as part of the query string. The naming convention is Model_Field for the id attribute and Model.Field for the name attribute.

I then used the bind parameter attribute with the prefix as follows:

[Bind(Prefix = "Model.FieldToRemotevalidate")] string FieldToRemoteValidate
Sign up to request clarification or add additional context in comments.

1 Comment

The odd part was that I had to specify the full name attribute in the prefix property overload where all the articles I read stated the prefix would be the part before the dot. Hope this might help someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.