單擊鏈接時(shí),我需要將 JavaScript 變量發(fā)送到 MVC 中的某個(gè) C# 控制器。我不想用 Jquery 來(lái)做。我需要用 JavaScript 來(lái)做。這是控制器的代碼: **[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()); }**我需要通過(guò)javascript向這個(gè)控制器發(fā)送3個(gè)參數(shù),第一個(gè)是元素的id,第二個(gè)是元素的屬性名,第三個(gè)是元素的值。謝謝,
1 回答

12345678_0001
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
如果我理解您在這里嘗試做的是使用純 JavaScript 調(diào)用端點(diǎn)?
這將為您完成工作:
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 關(guān)注
- 88 瀏覽
添加回答
舉報(bào)
0/150
提交
取消