user1929393
user1929393

Reputation: 4277

MVC how to set values metadata

I am doing testing of a form, it has many fields. I want to set the value of the fields so I do not have to keep re-entering it. Is there a way to set it in the class metadata area, where I also set it as Required type.

[MetadataType(typeof(myMetaData))]
public partial class myClass
{

    [Required]
    [Display(Name = "Zip")]
    public string Zip { get; set; }

    [Required]
    [Display(Name = "State")]
    public string State { get; set; }

    [Required]
    [Display(Name = "City")]
    public string City { get; set; }

Upvotes: 1

Views: 964

Answers (1)

Kundan Singh Chouhan
Kundan Singh Chouhan

Reputation: 14302

Use DefaultValue attribute for this.

[Required]
[Display(Name = "City")]
[DefaultValue("London")]
public string City { get; set; }

This will resolve your concern.

Upvotes: 1

Related Questions