i wanna pass 3 parameters from jquery call to web api method :
string[] a, string[] b, string[] c. but i can not .
<script type="text/javascript">
function fncsave() {
var arrtemplate = [];
var arrrole = [];
var arrpcode = [];
$('#mytemplateTags li').each(function () {
var str = $(this).html();
var res = str.match("<span class=\"tagit-label\">(.*?)</span>");
if (res!=null) {
var str = res[1];
arrtemplate.push(str);
}
});
$('#myroleTags li').each(function () {
var str = $(this).html();
var res = str.match("<span class=\"tagit-label\">(.*?)</span>");
if (res != null) {
var str = res[1];
arrrole.push(str);
}
});
$('#myprocessCodeTags li').each(function () {
var str = $(this).html();
var res = str.match("<span class=\"tagit-label\">(.*?)</span>");
if (res != null) {
var str = res[1];
arrpcode.push(str);
}
});
console.log(JSON.stringify(arrtemplate));
$.ajax({
url: "/api/TagCloud/SessionTemplate",
method: "Post",
data:JSON.stringify( { templates : arrtemplate, roles : arrrole, pcodes : arrpcode}),
async: false,
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (msg) {
console.log(msg);
if (msg == true) {
// alert("true");
}
}
});
}
</script>
C# codes :
[HttpPost]
public bool SessionTemplate(string[] templates, string[] roles, string[] pcodes)
{
HttpContext.Current.Session["templates"] = templates;
HttpContext.Current.Session["roles"] = roles;
HttpContext.Current.Session["pcodes"] = pcodes;
return true;
}
string[]as its members, and send a JSON. AFAIK you cannot pass multiple params to Web API POST method.