how to get the actual enum values instead of its int values
I have a enum class like below
public enum gender
{
male,
female,
others
}
and this is my model create method
public async Task<IActionResult> CreateCanditae(Canditateinfo caninfo)
{
if (ModelState.IsValid)
{
Canditateinfo canditateinfo = new Canditateinfo()
{
CanditateAadhar = caninfo.CanditateAadhar,
CanditateActDoa = caninfo.CanditateActDoa,
CanditateName = caninfo.CanditateName,
CanditateAddress = caninfo.CanditateAddress,
CanditateAltNumber = caninfo.CanditateAltNumber,
CanditateId = caninfo.CanditateId,
CanditateDepartment = caninfo.CanditateDepartment,
CanditateDesignation = caninfo.CanditateDesignation,
CanditateDoj = caninfo.CanditateDoj,
CanditateEmail = caninfo.CanditateEmail,
CanditateGender = caninfo.CanditateGender,
CanditateIdNumber = caninfo.CanditateIdNumber,
CanditateLocation = caninfo.CanditateLocation,
CanditateMaritialStatus = caninfo.CanditateMaritialStatus,
CanditatePancard = caninfo.CanditatePancard,
CanditateTeam = caninfo.CanditateTeam,
CanditateBaseLocation = caninfo.CanditateBaseLocation,
CanditateManager = caninfo.CanditateManager,
CanditateMobile = caninfo.CanditateMobile,
EnteredBy = HttpContext.Session.GetString("username"),
EnteredDate = DateTime.Now,
IsActive = 1,
DeleteFlag =0
};
_context.Canditateinfos.Add(canditateinfo);
_context.SaveChanges();
}
return View(nameof(Create));
}
i am saving this in mysql db. here when i save the gender it is showing as '1' instead of 'male' how to achieve it
i am saving this in mysql db. here when i save the gender it is showing as '1' instead of 'male' how to achieve it
in my model it is of type enum as follows
public gender Gender {get; set;}
i cant save it as int in db because they will use ssrs to take report.also i cant have a table for them in db because of the process.
CodePudding user response:
Enum.GetName will do this for you, but obviously you'll need to change that column in the database to something that can hold a string value, if you haven't already.
CodePudding user response:
//just pass it as a string in the database
enum.GetName(typeOf(male),1);