[英]How to send Json data and textbox data through jQuery ajax
I have a json collection and I want to send one textbox value to controller through jQuery ajax 我有一个json集合,我想通过jQuery ajax向控制器发送一个文本框值
$('#btnsave').click(function (e) {
debugger;
$.ajax({
type: "POST",
url: '/Asset/SaveAssociate',
data: "{'data':'"+JSON.stringify(allVals)+"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data);
// var gridk = $("#grid1").data("kendoGrid");
// gridk.dataSource.read();
}
})
})
and this is my textbox value 这是我的文本框值
var _assetid = $("#AssetId").val().trim();
like data: { json and assetid :assetid }
can I pass like this 像数据一样:
{ json and assetid :assetid }
我可以这样传递{ json and assetid :assetid }
This is my action method 这是我的行动方法
[NoCache]
public ActionResult SaveAssociate(string data, string AssetId)
{
JavaScriptSerializer json = new JavaScriptSerializer();
List<GetUserdata> myObjs = new List<GetUserdata>();
myObjs = json.Deserialize<List<GetUserdata>>(data);
for (int i = 0; i <= myObjs.Count; i++)
{
}
return Content("Hai");
}
I believed, this is what you want 我相信这就是你想要的
$('#btnsave').click(function (e) {
debugger;
var dataToSend={
'data':JSON.stringify(allVals),
'AssetId':$("#AssetId").val().trim()
};
$.ajax({
type: "POST",
url: '/Asset/SaveAssociate',
data: JSON.stringify(dataToSend),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data);
// var gridk = $("#grid1").data("kendoGrid");
// gridk.dataSource.read();
}
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.