Excel file not being downloaded when function is called via ajax method

Yes you are right you have problem with ajax, Basically you have to call the controller action again from you ajax call when your first ajax call return success. Add below code snippet to your ajax call.

success: function () {

    window.location = '@Url.Action("ExportExcel", "Profile")?id='+id;
}

And you have to change your controller method to return the file, as below

public FileResult ExportToExcelx()
{
	...............
	
	byte[] byteArray = Encoding.ASCII.GetBytes(sw.ToString());
	return File(byteArray, System.Net.Mime.MediaTypeNames.Application.Octet, "FileName.xlsx");                       
}