我有一个列表,我用javascript创建了它,我想将其发送到controller:
function submit1() {
var list_id = [];
var i;
for(i = 0; i < @Model.Count(); i++){
var x =docuzment.getElementsByClassName("bt1")[i].getAttribute("id");
var xxx = document.getElementById(x).style.backgroundColor;
if (xxx == "tomato") {
list_id.push(x);
}
}
$.ajax({
type: "POST",
url: '@Url.Action("add_invitations", "invitations")',
data: {list_id: String},
success: function (data) { alert("SUCCESS"); }
});
}
控制器:
public ActionResult add_invitations(List<string> ls )
{
ViewBag.a = ls.Count();
return View();
}
我总是得到ls>的空引用异常
javascript参考方案
您没有将正确的参数传递给action
,它期望得到名为ls
的参数,但是在您的data
对象中,您传递的是名为list_id
的参数。
尝试将其更改为此:
$.ajax({
type: "POST",
url: '@Url.Action("add_invitations", "invitations")',
data: {ls: list_id},
success: function (data) { alert("SUCCESS"); }
});
jQuery val函数在隐藏字段上不起作用? - javascript这是我的HTML代码:<div style='display:none;' id='allformid'> <div> <form action='#'> <input type='text' name='name' …
Mongo汇总 - javascript我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …
为HTML表单GET方法添加其他文本 - javascript使用表单的“ get”方法时,<form action="domain.com" method="get"> Surname: <input type="text" name="ABC"><br> Name: <input type=…
如何从客户端将数据插入数据库? - javascript我是Web开发的初学者,可以访问cpanel上托管的网站,并且需要对其进行一些更改。这个网站的后端是由蛋糕PHP制作的,我想使用ajax从客户端将一些数据插入其数据库。问题是我不知道如何获取负责插入数据库的PHP文件的URL。参见下面的代码:var xhttp = newXMLHttpRequest(); xhttp.onreadystatechange= …
编码JSON数据以保留json格式 - javascript由于JSON值是动态生成的,并且其中的值是基于用户输入的,因此,如果用户在字符串中输入了不可接受的字符(如"),则会使json无效。就像是:{ "tag" : "demo", "value": "user " input" } 有没有一种方法可以编码或转义JS…