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 7094015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:30:40+00:00 2026-05-28T08:30:40+00:00

I want to update Partial View via ajax, but it does not work. Look

  • 0

I want to update Partial View via ajax, but it does not work. Look at this model class:

   public class LogOnModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }

        public bool IsLoggedIn { get; set; }

        public string ReturnUrl { get; set; }
    }

the following view:

@model ITW2012Mobile.ViewModels.LogOnModel
<div id='LogOn' style="background-color: White;">
    @using (Ajax.BeginForm("LogOnAjax", "Home", new AjaxOptions { UpdateTargetId = "LogOn", OnSuccess = "logInComplete" }))
    { 
        ITW2012Mobile.ViewModels.LogOnModel m = Model;
        @Html.EditorFor(model => model.IsLoggedIn)
        @Html.EditorFor(model => model.ReturnUrl)
        <div>
            @Html.ValidationSummary()
        </div>
        <div>
            @Html.LabelFor(model => model.UserName)
            @Html.EditorFor(model => model.UserName)
        </div>
        <div>
            @Html.LabelFor(model => model.Password)
            @Html.EditorFor(model => model.Password)
        </div>
        <div>
            <input type="submit" value="Login" />
        </div>
    }
</div>

and the following controller class:

public ActionResult LogOnAjax(LogOnModel model)
{
    if (!User.Identity.IsAuthenticated)
    {
        if (ModelState.IsValid)
        {
            if (Membership.ValidateUser(model.UserName, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                model.IsLoggedIn = true;
                model.ReturnUrl = Url.Action("Index", "Home"); 
            }
            else
            {
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }
        }

        // If we got this far, something failed, redisplay form
        return PartialView("PartialViewAjaxLogOn", model);
    }
    else
    {
        return PartialView("PartialViewLogOut");
    }
}

even when username/password are correct and IsLoggedIn = true and ReturnUrl!=empty view shows empty fields for these variables (but debugger shows values inside). Why and how to make it correctly?

  • 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-05-28T08:30:41+00:00Added an answer on May 28, 2026 at 8:30 am

    Try clearing the values you are modifying in your action from modelstate or if you use them in html helpers the old values will be used:

    ModelState.Remove("IsLoggedIn");
    model.IsLoggedIn = true;
    ModelState.Remove("ReturnUrl");
    model.ReturnUrl = Url.Action("Index", "Home"); 
    

    Also bear in mind that upon successful authentication and cookie emission you should not display a view (partial in your case). You should redirect so that the authentication cookie is sent by the client on the subsequent request. You should redirect to the return url. But since you are doing this using AJAX you should probably send some indication to the client that the authentication was successful so that you can redirect on the client.

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

Sidebar

Related Questions

ViewData.Model.ExecuteResult does not exist in ASP.NET MVC2, but in MVC1. What is the alternative
I want to update the partial view every time the ActionLink is clicked. I'm
Is it possible to do a partial update through linq2sql? If I want to
i want to update my sqlite database but i cannot find the way to
I want to update a .class file in a jar with a new one.
I generate my jqgrid from model class which I pass into view. I get
This should be really easy, I just want to update the listview when the
I have a strong typed partial view of a class that contains a list
I’m developing MVC application and I have following classes in my model: public class
I want update a column by adding days to current time. In pseudosyntax it

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.