Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • ID 27 posts 128 karma points
    Mar 05, 2013 @ 14:00

    TempData.Add or ModelState.AddModelError to pass "Invalid username or password"


    I am creating a Surface controller for the member login. I was just wandering what I should use for passing the validation message to the view.


    • TempData.Add("Status", "Invalid username or password");
    • ModelState.AddModelError("Status", "Invalid username or password");


    What's the difference and what's best practice here?




  • Andreas Iseli 150 posts 427 karma points
    Mar 06, 2013 @ 12:07
    Andreas Iseli

    The easies way is to use attributes on the models properties for the validation. The modelstate the automatically adds the invalidation message. Anyway when doing it directly, use the "ModelState.AddModelError(...)" method.

Please Sign in or register to post replies

Write your reply to: