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

  • Home
  • SEARCH
  • 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 6079301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:55:52+00:00 2026-05-23T10:55:52+00:00

Right now I’m trying to have an Ajax window open another window on completion.

  • 0

Right now I’m trying to have an Ajax window open another window on completion. Basically, the first window asks if the user wants to do something and the second tells them it was successful. The first needs a yes or no and the second just needs an ok. How do I tell the Ajax Actionlink to open another one when its done? I’m working in MVC 3 with C#.

Right now my ActionLink is:

@Ajax.ActionLink("Reset User Password", "ResetUserPW", "Admin", 
new { userName = Model.UserName }, 
new AjaxOptions { Confirm = "Reset Password?", HttpMethod = "HttpGet" })

This works fine (I know there is no OnSuccess bit, that fact is mentioned later). It executes the logic fine and resets the user’s password. I just can’t figure out how to get it to open another window. Here’s my Controller Action:

    public ActionResult ResetUserPW(string userName)
    {
        string newExcept;
        MembershipUser user = Membership.GetUser(userName);
        if (user != null)
        {
            try
            {
                string newPassword = Membership.GeneratePassword(8, 2);
                if (user.ChangePassword(user.GetPassword(), newPassword))
                {
                    var mailMessage = new UserMailer();
                    return PartialView();
                    //return RedirectToAction("Users"); //Tried this return 
                                                          result, no go
                }
                else
                {
                    const string ErroExcept = "There was an error processing your request (the password reset has failed). Please try again.";
                    ModelState.AddModelError("", ErroExcept);
                }
            }
            catch (Exception ex)
            {
                newExcept = String.Format("There was an error processing your request({0}). Please try again.", ex.Message);
                ModelState.AddModelError("", newExcept);
            }
        }
        else
        {
            newExcept = "There is no record of the specified user in the database.";
            ModelState.AddModelError("", newExcept);
        }
        return RedirectToAction("Users");
    }

It never gets to the last line of code since it executes correctly. There are no data tags at the top, though I have tried changing the HttpMethod to a POST one and adding the POST tag. Also, I am very much so aware that there is no OnSuccess or OnCompletion in the ActionLink. I tried putting a whole lot of different things in there and got no results, so I trimmed them. And after all, the entire question is what do I put in the OnSuccess = area?

I’m not too great or familiar with JQuery and I think thats why this is so hard for me to solve. I’ve searched exhaustively and written tons of different types of JQuery code, but could not use any of them with the Ajax link. The Controller action accepts the userName since the Admin does this action and will need to do it for all users (said to stop the inevitable: “You can get the user’s user name with User.Identity.name” statement). Also, tell me if trimming the exceptions and ModelState code would be helpful. Thanks in advance.

Final Solution:

public ActionResult ResetUserPW(string userName)
{
    string newExcept;
    MembershipUser user = Membership.GetUser(userName);
    if (user != null)
    {
        try
        {
            string newPassword = Membership.GeneratePassword(8, 2);
            if (user.ChangePassword(user.GetPassword(), newPassword))
            {
                var mailMessage = new UserMailer();
                mailMessage.AdminPWReset(user.UserName, newPassword, user.Email.SendAsync();
                return Json(null);
            }
            else
            {
                ModelState.AddModelError("Password", "There was an error processing your request (the password reset has failed). Please try again");
            }
        }
        catch (Exception ex)
        {
            ModelState.AddModelError("Password", String.Format("There was an error processing your request ({0}). Please try again.", ex.Message));
        }
     }
     else
     {
        ModelState.AddModelError("Invalid User", "There is no record of the specified user in the database.");
     }

     if (!ModelState.IsValid)
     {
        return Json(GetModelStateErrors(ModelState));
     }

     return Json(null);
}    

There are no verbs at the top.
GetModelStateErrors is defined as such:

private IEnumerable<ModelStateError> GetModelStateErrors(ModelStateDictionary dictionary)
{
    foreach(var key in dictionary.Keys)
    {
        var error = dictionary[key].Errors.FirstOrDefault();
        if(error != null)
            yield return new ModelStateError(key, error.ErrorMessage);
    }
}

And finally, the Ajax link is:

@Ajax.ActionLink("Reset User Password", "ResetUserPW", "Admin",
new { userName = Model.UserName }, 
new AjaxOptions { 
     Confirm = "Reset Password?", 
     HttpMethod = "HttpGet", 
     OnSuccess="success" 
     })

Whoopsies, forgot to add the final Javascript I used. Its the same as the one gram said:

<script type="text/javascript">
function success(data) {
    alert('You have successfully reset the user\'s password!');
}
</script>
  • 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-23T10:55:52+00:00Added an answer on May 23, 2026 at 10:55 am

    You can put a javascript callback in OnSuccess that will run if the AjaxLink call returns a non-error status, like so:

    <script src="../../Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script type="text/javascript">
        function success(data) {
            alert('Your password was reset');
        }
    </script>
    
    @Ajax.ActionLink("Reset User Password", "ResetUserPW", "Admin", 
        new { userName = Model.UserName }, 
        new AjaxOptions { Confirm = "Reset Password?", HttpMethod = "HttpPost", OnSuccess = "success" })
    

    But you need a way to return validation errors. So I would try something like this:

    [HttpPost]
     public ActionResult ResetUserPW(string userName) {
        string newExcept;
        MembershipUser user = Membership.GetUser(userName);
        if (user != null) {
            try {
                string newPassword = Membership.GeneratePassword(8, 2);
                if (user.ChangePassword(user.GetPassword(), newPassword)) {
                    var mailMessage = new UserMailer();
                }
                else {
                    ModelState.AddModelError("Password", "There was an error processing your request (the password reset has failed). Please try again.");
                }
            }
            catch (Exception ex) {
                ModelState.AddModelError("Password", String.Format("There was an error processing your request({0}). Please try again.", ex.Message));
            }
        }
        else {
            ModelState.AddModelError("Password", "There is no record of the specified user in the database.");
        }
    
        if (!ModelState.IsValid)
            return Json(GetModelStateStateErrors(ModelState));
    
        return Json(null);
    }
    
    private IEnumerable<ModelStateError> GetModelStateStateErrors(ModelStateDictionary dictionary) {
        foreach (var key in dictionary.Keys) {
            var error = dictionary[key].Errors.FirstOrDefault();
            if (error != null)
                yield return new ModelStateError(key, error.ErrorMessage);
        }
    }
    

    with a simple DTO for ModelState:

    public class ModelStateError {
        public string Property { get; set; }
        public string Error { get; set; }
    
        public ModelStateError(string key, string value) {
            this.Property = key;
            this.Error = value;
        }
    }
    

    If there are no validation errors, the data parameter in success will be null, otherwise, it will contain an array of validation errors that you can present to the user however you want.

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

Sidebar

Related Questions

Right now, I have three models Post, Comment and User (using Devise ) associated
Right now I'm asking the user for two numbers. I'm trying to print the
Right now I have the following query: User.find(:all, :conditions => [guest = ? AND
Right now i have this ***FIRST***1DESIGNRESULTSM25Fe415 ***Second***Fe415 ***Third***1500.0mm ***Fourth***300.0mmX600.0mmCOVER:40.0mm ***Fifth***15ENDJOINT:13SHORTCOLUMN ***Sixth***5472.00Sq.mm.REQD.CONCRETEAREA:174528.00Sq.mm ***Seventh***12-25dia.(3.27%,5890.49Sq.mm.)(Equallydistributed) ***Eighth***8mm ***Ninth***300mmc/c
Right now, what I have is, when the user clicks on the page, the
Right now I have an asp:Wizard with 3 Steps. Create User Form to Email
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I have an SSIS package that runs every morning and gives me
Right now, I have two Eclipse projects - they both use Maven 2 for
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName

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.