单击链接时,我需要将 JavaScript 变量发送到 MVC 中的某个 C# 控制器。我不想用 Jquery 来做。我需要用 JavaScript 来做。这是控制器的代码: **[HttpPost] public ActionResult saveuser(int id, string propertyName, string value) { var status = false; var message = ""; //Update data to database using (PaediatricDBEntities db = new PaediatricDBEntities()) { var user = db.ShiftTypes.Find(id); if (user != null) { db.Entry(user).Property(propertyName).CurrentValue = value; db.SaveChanges(); status = true; } else { message = "Error!"; } } var response = new { value = value, status = status, message = message }; JObject o = JObject.FromObject(response); return Content(o.ToString()); }**我需要通过javascript向这个控制器发送3个参数,第一个是元素的id,第二个是元素的属性名,第三个是元素的值。谢谢,
1 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
如果我理解您在这里尝试做的是使用纯 JavaScript 调用端点?
这将为您完成工作:
function callYourController(id, propertyName, value) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhttp.open("POST", "www.google.com?id=" + id + "&propertyName=" + propertyName + "&value=" + value, true);
xhttp.send();
}
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报
0/150
提交
取消
