Mastering Development

ASP.NET Core how to randomly set property value

In ASP.NET Core, I need to set a property to a random string, but the random string will be generated from another property. The properties are

public class State
    public int Id {get;set;}
    public string Name {get;set;}
    public string Capital {get;set;}
    public string RandomCapital {get;set;}

Basically Capital has values state capitals as its values, and I need to set RandomCapital to random instances of Capital or random values, I am trying to do it using linq. In my controller all I have is a way to generate random values, but not set properties to random values. I know that if i put this in the controller it will generate x number of random values, but how do I set values?

public async Task<IActionResult> SetValues()
    Random random = new Random();
    var quiz = _context.States.OrderBy(c => random.Next()).Take(x);
    return View(quiz);

Leave a Reply

Your email address will not be published. Required fields are marked *