Modified my code by taking reference to your suggestion because I have nothing to return from SP.
Repository class:
public void ExecuteWithoutReturn() //7 params are passed here
{
using (MySqlConnection con = new MySqlConnection(ConnectionString))
{
using (MySqlCommand cmd = new MySqlCommand(procedureName, con))
{
con.Open();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@studyNameSource", _studyNameSource);
cmd.Parameters.AddWithValue("@scenarioNameSource", _scenarioNameSource);
cmd.Parameters.AddWithValue("@studyNameDestiny", _studyNameDestiny);
cmd.Parameters.AddWithValue("@scenarioNameDestiny", _scenarioNameDestiny);
cmd.Parameters.AddWithValue("@projectNameDestinyArray", _projectNameDestinyArray);
cmd.Parameters.AddWithValue("@mappingType", _mappingType);
cmd.ExecuteNonQuery();
}
con.Close();
}
}
Controller Method:
[HttpPost]
public ActionResult ExecuteDuplicateMapping(ViewModel dmViewMode)
{
try
{
string procedureName = "DuplicateMapping";
_repository.ExecuteWithoutReturn(procedureName, dmViewMode.SourceStudyName, dmViewMode.SourceScenarioName, dmViewMode.TargetStudyName, dmViewMode.TargetScenarioName, dmViewModel.newPrj, dmViewModel.mappingType);
return Json(new { success = true, responseText = "Executed successfuly!" });
}
catch (Exception ex)
{
throw ex;
}
}
Index View:
function DuplicateMapping(sourceStudy, sourceScenario, targetStudy, targetScenario, selectedT) {
var actionUrl = "@Url.Action("ExecuteDuplicateMapping", "Map")";
$.ajax({
type: 'POST',
url: actionUrl,
dataType: 'json',
data: {
SourceStudyName: sourceStudy,
SourceScenarioName: sourceScenario,
TargetStudyName: targetStudy,
TargetScenarioName: targetScenario,
TargetProjectName: selectedT
},
success: function (response) {
if (response.success) {
alert(response.responseText);
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Error!");
}
});
}
thank you so much