我有隱藏字段asp.net的MVC的jQuery發佈多個隱藏字段
<input type="hidden" value="1" id="serviceslist" name="serviceslist" />
<input type="hidden" value="2" id="serviceslist" name="serviceslist" />
<input type="hidden" value="3" id="serviceslist" name="serviceslist" />
我有添加更多按鈕,點擊它時,這個名單要發送的serviceslist MVC的控制器。基本上我認爲我需要發送列表作爲數組。我該怎麼做?
$('#addmoreservices').click(function() {
var serviceslist= $("#serviceslist").val()
$.ajax({
url: url,
data: { serviceslist: serviceslist },
cache: false,
dataType: "json",
traditional: true,
type: "POST",
success: function (data) {
alert("dddd");
},
error: function (reponse) {
alert("error : " + reponse);
}
});
});
這是我的MVC控制器
[HttpPost]
public ActionResult AddmoreServices(List<int> serviceslist)
{
return View();
}
'id'應該是唯一的 –