Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:43:43+00:00 2026-06-15T16:43:43+00:00

This question has been asked many times but I don’t think the way I

  • 0

This question has been asked many times but I don’t think the way I need it.

I’m trying to implement a login form on the home page but this form is located in a section that pops up, like you have on this site: http://myanimelist.net.

I’ve created a partial view for my login form:

@model ArtWebShop.Models.customers

@section Validation {
    @Scripts.Render("~/bundles/jqueryval")
}

<section id="login">

    @using (Html.BeginForm("LoginValidate", "Login", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.ValidationSummary(true)
        @Html.ValidationSummary()
        <fieldset>
            <legend>Login</legend>

            @Html.LabelFor(model => model.email)
            @Html.TextBoxFor(m => m.email) 

            @Html.LabelFor(m => m.password)
            @Html.PasswordFor(m => m.password)

            <input type="submit" value="Login" class="button" />
        </fieldset>
    }

</section>

This is shown on the home page (index.cshtml):

<section class="shown">
    @Html.Partial("_LoginPartial")
    @Html.ValidationSummary(true)
    @Html.ValidationSummary()
</section>

The partial view is shown correctly.
But now comes the part that doesn’t work.

When you press login if you haven’t filled in the fields, the validation is done in my LoginController as it should but I can’t seem the send the errors to my home page view when I redirect.

    [HttpPost]
    public ActionResult LoginValidate(string redirect)
    {
        if (_unitOfWork.CustomersRepository.CostumerIsValid(Request.Form["email"], Request.Form["password"]))
        {
            if (!String.IsNullOrEmpty(redirect) || String.Compare(redirect, "none", StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (redirect != null) Response.Redirect(redirect, true);
            }
            else
            {
                return RedirectToAction("index", "Home");
            }
        }
        ModelState.AddModelError("email", "You entered an incorrect email address");
        ModelState.AddModelError("password", "You entered an invalid password");

        return RedirectToAction("index", "Home");
    }

That’s my loginValidation. Since nothing is filled in the errors are added to the ModelState and then it redirects to the home page. This however doesn’t shows me the errors.I’m guessing it’s exactly because I redirect but how can I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:43:44+00:00Added an answer on June 15, 2026 at 4:43 pm

    You can use TempDataDictionary to store the ModelStateDictionary between redirects.

    TempDataDictionary Class
    Represents a set of data that persists only from one request to the next.

    In your LoginValidate action you would store the ModelState like so:

    public ActionResult LoginValidate(string redirect)
    {
        /* Your other code here (omitted for better readability) */
    
        ModelState.AddModelError("email", "You entered an incorrect email address");
        ModelState.AddModelError("password", "You entered an invalid password");
    
        // Add the ModelState dictionary to TempData here.
        TempData["ModelState"] = ModelState;
    
        return RedirectToAction("index", "Home");
    }
    

    And in your HomeController, Index action you would check if the TempData has a ModelState:

    public ActionResult Index()
    {
        var modelState = TempData["ModelState"] as ModelStateDictionary;
        if (modelState != null)
        {
            ModelState.Merge(modelState);
        }
    
        return View();
    }
    

    You could make this a little bit cleaner by using custom action filters; see this blog, number 13.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this question has been asked many a times but I've been searching
I see that this question has been asked many times but I think my
I think this is a question that has been asked many times but I
Maybe this question has been asked many times before, but I never found a
This question has been asked many times before, but they all seem to relate
I am aware this question has been asked many times but I just cannot
I know this question has been asked many times on SO, but none of
I know this question has been asked many times, but I'm looking for a
I know this question has been asked many times, but I couldn't manage to
I know this question has been asked many times. But from what I read,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.