0

When I send some data in the database and the text is successful, it should be notified and if there is an error, it should give a mistake.

The message must be displayed on Create or Login, but it depends on whether it is succe or error.

AccountViews model = new AccountViews();
var mail = model.Email;
var result = _dbContext.Users.FirstOrDefault(i => i.Brugernavn == mail);
if(result == null)
{

    model.Message = "Succes";

    return RedirectToAction("Login");
}

model.Message = "Error";

return RedirectToAction("Create");

In my model I have:

[TempData]
public string Message { get; set; }
public bool ShowMessage => !string.IsNullOrEmpty(Message);

Then the question here is how can I get my message to appear?

The problem is, as I see it, that how I get my message to appear on the page when I send me / someone over to another page.

I work in MVC - .Net core 2.0

Paul Michaels
  • 16,185
  • 43
  • 146
  • 269

1 Answers1

0

you can pass it using query string like this:

RedirectToAction("Create", new { error= "ErrorMsg" });

So to get this in your destination Action you should add an argument to your create action:

public ActionResult Create(string error){
//do what you want with error
//to show this in view you can use viewbag like:
ViewBag.Error = error;
return View();
}

then you can show it as easy as call it in your Create view file like:

<div> @ViewBag.Error <div>
Iman Fakhari
  • 83
  • 1
  • 2
  • 8