1

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....

1
  • @DStanley I'd guess @Url.Action("Login", model) - since OP wants to have single model for action and view all fields of the model will endup in the url (probably including plain text password to make it even more ridiculous). Commented Dec 3, 2014 at 17:32

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.