C
C#4w ago
elementabg

Issues with ASP.NET Core Unobtrusive Validation on Dynamically Added Form Elements

Hello everyone, I'm having issues with unobtrusive validation in ASP.NET Core not working correctly on dynamically added form elements. I have a form with multiple input fields that can be dynamically added via JavaScript. I'm using jQuery and jQuery Unobtrusive Validation to handle client-side validation. When adding new input fields, I am re-initializing the unobtrusive validation using $.validator.unobtrusive.parse("form"); My models:
public class BetSlipBindingModel
{
public BettingSlipType Type { get; set; }

public BettingMode Mode { get; set; }

public IList<FixtureBetBindingModel> FixtureBets { get; set; }
}

public class FixtureBetBindingModel
{
[Required]
[StringLength(GameMaxLength)]
public string Game { get; set; } = null!;

[Required]
[StringLength(PredictionMaxLength)]
public string Prediction { get; set; } = null!;

public SportType Sport { get; set; }

[Range(MinOddValue, MaxOddValue)]
public double Odd { get; set; }
}
public class BetSlipBindingModel
{
public BettingSlipType Type { get; set; }

public BettingMode Mode { get; set; }

public IList<FixtureBetBindingModel> FixtureBets { get; set; }
}

public class FixtureBetBindingModel
{
[Required]
[StringLength(GameMaxLength)]
public string Game { get; set; } = null!;

[Required]
[StringLength(PredictionMaxLength)]
public string Prediction { get; set; } = null!;

public SportType Sport { get; set; }

[Range(MinOddValue, MaxOddValue)]
public double Odd { get; set; }
}
My view
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?