Reputation: 2653
I realize this is probably simple but all my attempts/research has come up empty.
I've got the following in my view
@if (Model.HasError)
{
<div class="alert alert-danger" role="alert">
Username or password is incorrect
</div>
}
and my controller looks more or less like
public ActionResult Login(User model)
{
model.HasError = true;
return View(model);
}
This produces the desired result and the message displays. However, the url is also populated with all the values from the model as well. I really just want the HasError
property of the model to show.
Is there a better way to go about doing this? I looked at having two different models but it seemed like a lot to just hide/show an element....
Upvotes: 1
Views: 687
Reputation: 152654
You could just create a new User
object and just set the HasError
property:
public ActionResult Login(User model)
{
return View(new User() {HasError = true});
}
But it's not clear what URL you are seeing to know if this is the right method.
Upvotes: 1