2

I have an view model

public class fooViewModel
{
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }
    [Required]
    [CustomAttribute]
    public float foo1{ get; set; }
    [Required]
    [CustomAttribute]
    public decimal foo2 { get; set; }
}

I made a custom server side validation attribute.

[AttributeUsage(AttributeTargets.Property)]
public class CustomAttribute : RequiredAttribute
{
    public CustomAttribute()
    {
        ErrorMessage = "Some message";
    }

    public override bool IsValid(object value)
    {
        string input = value.ToString();
        //some validation logic
        return result;
    }
}

The problem is that when I use a dot "." in the input field for either foo1 or foo2 the decimal and the float don't get any value... I know this has something to do with cultures... anyway is there a way to fix it without using a string for foo1 and foo2? PS: When I use a comma "," for the numbers the jquery strikes in an says it's an invalid number (jQuery unobtrusive)... I know it has something to do with cultures but ...

peter
  • 69
  • 1
  • 6

0 Answers0