mardi 3 novembre 2020

Set random value to model property - C# [duplicate]

I want to generate a random number for Student model's PaymentNumber property. For each student unique random number (6 digit) must be generated when student object is created (when student applies).

Student.cs:

namespace CourseApp.Models
{
    public class Student
    {
        public string Name { get; set; }
        public string Mail { get; set; }
        public string Phone { get; set; }
        public int PaymentNumber { get; set; }
    }
}

CourseController:

[HttpPost]
public IActionResult Apply(Student student)
{
  if(ModelState.IsValid)
    {
      Repository.AddStudent(student);
      return View("Thanks", student);
    }
  else
    {
      return View(student);
    }
}



Aucun commentaire:

Enregistrer un commentaire