Hi All,
I'm calling async Task<ActionResult> from ajax, and its working, I'm calling another view from this Task<ActionResult>, but when the code finish in Task<ActionResult> the view doesn't load, it still in base View.
Ajax:
function Edit(idEmployee) {$.ajax({
url: '@Url.Action("EditEmployee/id","Employees")'.replace('id', idMain),
type: 'post',
dataType: 'json',
contentType: 'application/json;charset=utf-8',
success: function () {
},
error: function (error) {
alert(error.statusText);
}
});
}Code C#
[HttpPost]
public async Task<ActionResult> EditEmployee(int id)
{
vmEmployee VMemployee = new vmEmployee();
Employee emp = new Employee();
string apiUrl = ConfigurationManager.AppSettings["baseurl"] + "/EMPLOYEE.API/LoadEmployee";
var client = new HttpClient();
client.BaseAddress = new Uri(apiUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage responseMessage = await client.PostAsJsonAsync(apiUrl,id);
if (responseMessage.IsSuccessStatusCode)
{
var responseData = responseMessage.Content.ReadAsStringAsync().Result;
emp = JsonConvert.DeserializeObject<Employee>(responseData);
}
VMemployee.Employee= emp;
return View("NewEmployeePage",VMemployee );
}Everything it is working fine, and the API working for retrieve object Employee, but this ajax method in View ( Employee List ) when user click on edit, I need to move to View(New Employee)... but it is not working.
By the way I mentioned in ajax > error ( alert(error.statusText)) ..... when code of Task<ActionResult> finish, I found alert > OK ???. why the ajax going to error but I didn't found any error when I made a debug with the code?
I have one controller > Employee
I have two action method / Views in this controller > 1. EmployeeList which the one has the ajax method. 2. NewEmployeePage , which I want to move to.