mvc-unable to make ajax call to controller

I am trying to call my “Account” controller action “ChangePassword” by ajax call.But it says 500 error for controller action.I have tried with or without data but for both it shows same 500 error.

ChangePassword model

  public class ChangePasswordVM
    [StringLength(100, ErrorMessage = "The Old Password must be at least {2} characters long.", MinimumLength = 6)]        
    [DisplayName("Old Password")]
    public string OldPassword { get; set; }

    [StringLength(100, ErrorMessage = "The Password must be at least {2} characters long.", MinimumLength = 6)]
    //[RegularExpression(@"^(?=.*d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^da-zA-Z])(.{8,15})$", ErrorMessage = "Your password must be between 8 - 15 characters long. It must contain atleast one uppercase,one lowercase,one non-alphabet either number or special character. ")]
    [DisplayName("New Password")]
    public string Password { get; set; }

    [DisplayName("Confirm Password")]
    [System.Web.Mvc.Compare("Password", ErrorMessage = "New Password and confirm password do not match")]
    public string ConfirmPassword { get; set; }

    public AuthenticationProvider AuthProvider { get; set; }

ajax call

  <script type="text/javascript">

    function ChangePassword() {
        var model = JSON.stringify({ 'OldPassword': $("#oldPassword").val(), 'Password': $("#newPassword").val(), 'ConfirmPassword': $("#confirmPassword").val() });
        cache: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        type: "POST",
        data: model,
        url: '@Url.Action("ChangePassword", "Account")',
        success: function (data) {



    public ActionResult ChangePassword(ChangePasswordVM model)
        if (!ModelState.IsValid)
            return Json(model);

        UserBO user;
        string token;
        PublicLayer.AuthenticateUser(SessionItems.EmailAddress, model.OldPassword, out user, out token);
        if (user == null)
            ModelState.AddModelError("OldPassword", Messages.InvalidPassword);
            return Json(model);
            //return RedirectToAction("MyProfile");

        var salt = Guid.NewGuid();
        user.PasswordSalt = salt;
        user.Password = EncryptionHelper.EncryptPassword(salt.ToString(), model.Password);
        ViewBag.IsPasswordChanged = AdminLayer.UpdateUser(user);

        return RedirectToAction("MyProfile");


<div class="form-group">
        <div class="col-sm-offset-3 col-sm-5">
            <button class="btn btn-sm btn-primary" onclick="ChangePassword()">Update</button>

Source: ajax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.