The Objective:
Execute a javascript function on $.ajax named on server side and get it on result.
The Problem:
On data.ExecuteClientCode I’ll get the name of the function that I should execute in that case : "AfterFamilySelectedUpdateParameters()" but my problem is that i don’t know how to set that string in order to be executed.
The code:
view:
function AfterFamilySelected()
{
$.ajax({
url: "/@Model.ControllerAfterEntitySelected/@Model.ActionAfterEntitySelected" ,
type: "POST",
async: false,
success: function(data, status, xhr) {
**data.ExecuteClientCode;**
},
error: function(xhr, status, err) {
alert('error');
}
});
}
controller:
[HttpPost]
public ActionResult AfterFamilySelected()
{
return Json(new { ExecuteClientCode = "AfterFamilySelectedUpdateParameters()" });
}
Assuming the method is attached to the window you could do:
Server
Client
You would need to remove the brackets from the value you return from the server.