This is my controller:
public async Task<IActionResult>ActiveEmailAccount(EmailActiveAccountViewModel active)
{
if (ModelState.IsValid)
{
var result = await _userService.ActiveAccount(active);
switch (result)
{
case ActiveEmailResult.Error:
ModelState.AddModelError("CustomError", "You Have Error ");
break;
case ActiveEmailResult.NotActive:
ModelState.AddModelError("CustomError", "You Are not Active. ");
break;
case ActiveEmailResult.Success:
ModelState.AddModelError("CustomError", "You Are Active ");
break;
}
ViewData["Active"] = result;
}
return View(active);
}
I want to show result of View data in view. I know it is
<p> @(ViewData["Active"] </P>
I want to know how can I show these results in different status with different class?
for example if was success: with class="alert-success"
if was not active with class alert-danger.....
Inside the switch-case statement in your action you can set a
ViewDataentry with the alert class for each case:Then in your view you can use
Html.ValidationMessagehtml helper to get the model state message andViewDatato get the alert class:Razor solution:
You can use a switch-case statement inside your view: