Copied to clipboard

Flag this post as spam?

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


  • Girish Khadse 52 posts 132 karma points
    Apr 02, 2013 @ 07:33
    Girish Khadse
    0

    How to add error state to the partially rendered view

    Hi...

    I have a home screen in which I have header footer and some content. In the content area, I am rendering login control as a partial view. Now I am trying to provied validations to login control. Here is code of my surface controller for login 

     [HttpPost]
            [ActionName("Login")]
           public ActionResult Login(LoginCommand command)
           {
               if (ModelState.IsValid)
               {
                   if (Membership.ValidateUser(command.Username, command.Password))
                   {
                       FormsAuthentication.SetAuthCookie(command.Username, command.RememberMe);
                       if (command.RememberMe)
                       {
                           Response.Cookies["UserName"].Value = command.Username;
                           Response.Cookies["Password"].Value = command.Password;
                       }
                       return PartialView("Details", command);              
                   }
                   else
                   {
                       ModelState.AddModelError("Login", "Invalid username or password");
                       return PartialView("Login", new LoginCommand());
                   }
               }
               return PartialView("Login", new LoginCommand());
           }

    But when I return partial view with error, it is being rendered in a new page, not in the same location( in the home page). How should we render the view with error state in the home screen also by preserving model state?

Please Sign in or register to post replies

Write your reply to:

Draft