1
Ich möchte über Ajax Aufruf der C# -Methode (unten) von jquery sprechen? Unterhalb von Codes (js) kann kein Wert an "SessionTemplate (List-Liste)" gesendet werden. Wie kann ich die Werteliste übergeben?So rufen Sie die Liste <string> Typ-Parameter-Methode von Ajax aufrufen?
[HttpPost]
public bool SessionTemplate(List<string> list)
{
HttpContext.Current.Session["templates"] = list;
return true;
}
Aufruf der Methode: (nicht funktioniert)
function fncsave() {
var arrtemplate = [];
$('#mytemplateTags li').each(function() {
var str = $(this).html();
var res = str.match("<span class=\"tagit-label\">(.*?)</span>");
if (res!=null) {
var str = res[1];
alert(str);
arrtemplate.push(str);
}
});
console.log(arrtemplate);
var jsondata = { arrtemplate };
$.ajax({
url: "/api/TagCloud/SessionTemplate",
method: "Post",
data: jsondata,
async: false,
dataType: "json",
success: function (msg) {
console.log(msg);
if (msg == true) {
alert("true");
}
}
});
Ist der MVC oder WebForms? Ich nehme an, wie Sie HttpPost verwenden, ist es MVC? –
Hallo; es ist webapi asp.net – Penguen