1

Remote validation happens only for 1st element. For other elements null value goes in the parameter so no validation happens. Why is it passing null values for rest of the rows? Only row 0 values are passed. What am I doing wrong? Or is there alternative to do the validation?

My model:

public class AdminModel
{
    ....

    public List<Detail> ManageDetails { get; set; }
}

public class Detail
{
    public string Id { get; set; }
    [Remote("CheckValidity", "", AdditionalFields = "InDate, OutDate", ErrorMessage = "Time is invalid.")]
    public string InTime { get; set; }
}

The view is rendered with a for loop:

@for (int index = 0; index < Model.ManageDetails.Count; index++)
{
     @Html.HiddenFor(model => model.ManageDetails[index].Id)
     @Html.TextBoxFor(model => model.ManageDetails[index].InTime})
     @Html.ValidationMessageFor(model => model.ManageDertails[index].InTime)
}
Raj
  • 166
  • 1
  • 11
  • Refer [this answer](http://stackoverflow.com/questions/27513472/remote-validation-for-list-of-models/27517407#27517407) for an explanation of why it does not work and a suggested work around –  Oct 07 '15 at 05:55
  • thanks Stephen. There also similar question which I looked at http://stackoverflow.com/questions/20415648/remoteattribute-not-passing-querystring-as-ienumerablet-correctly/ but it is not working for me. – Raj Oct 07 '15 at 06:49
  • My answer that I linked to above did not address the added problem of using `AdditionalFields` but I you look at the link to the [CodePlex issue](https://aspnetwebstack.codeplex.com/workitem/2213) I submitted, you will see a suggested solution (note: I have not tested it myself yet but it looks good) –  Oct 07 '15 at 06:54
  • Stephen, thanks a lot, that additional field code worked for me. Just needed only that code. I am not sure if that code will affect anything else or if I need to test something else to verify that code works fine. I will go by this solution right now. thanks again. – Raj Oct 07 '15 at 09:22
  • OK, I'll mark this as a dupe, so others coming across this can get to the answer –  Oct 07 '15 at 09:24
  • Stephen that code change does messes with radio button values, it passes null for them. The same code was working without this change. Not an expert in javascript so can't point where the error could be. – Raj Oct 08 '15 at 09:16

0 Answers0