Skip to content

Commit

Permalink
Merge pull request #6352 from abpframework/maliming/dataType
Browse files Browse the repository at this point in the history
Set dataType to text for string return values for dynamic JavaScript proxies.
  • Loading branch information
realLiangshiwei committed Dec 1, 2020
2 parents d2d873a + 5f7f388 commit c615aed
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public string CreateScript(ApplicationApiDescriptionModel model)

script.AppendLine("/* This file is automatically generated by ABP framework to use MVC Controllers from javascript. */");
script.AppendLine();

foreach (var module in model.Modules.Values)
{
script.AppendLine();
Expand Down Expand Up @@ -99,9 +99,12 @@ private static void AddActionScript(StringBuilder script, string controllerName,
AddAjaxCallParameters(script, action);

var ajaxParamsIsFromForm = action.Parameters.Any(x => x.BindingSourceId == ParameterBindingSources.Form);
var dataType = action.ReturnValue.Type == ReturnValueApiDescriptionModel.Create(typeof(string)).Type
? "{ dataType: 'text' }, "
: string.Empty;
script.AppendLine(ajaxParamsIsFromForm
? " }, $.extend(true, {}, ajaxParams, { contentType: 'application/x-www-form-urlencoded; charset=UTF-8' })));"
: " }, ajaxParams));");
? " }, $.extend(true, {}, " + dataType + "{ contentType: 'application/x-www-form-urlencoded; charset=UTF-8' }, ajaxParams)));"
: " }, " + dataType + "ajaxParams));");

script.AppendLine(" };");
}
Expand Down Expand Up @@ -159,7 +162,7 @@ private static void AddAjaxCallParameters(StringBuilder script, ActionApiDescrip
script.Append(" data: " + formData);
}
}

script.AppendLine();
}

Expand Down Expand Up @@ -191,7 +194,7 @@ private static Dictionary<ActionApiDescriptionModel, string> CalculateNormalized

return result;
}

private static void AddInitializedEventTrigger(StringBuilder script)
{
script.AppendLine();
Expand All @@ -213,4 +216,4 @@ private static string CamelCaseWithNamespace(string name)
return name.Split('.').Select(n => n.ToCamelCase()).JoinAsString(".");
}
}
}
}

0 comments on commit c615aed

Please sign in to comment.