如何使用来自jquery的var正确处理代码,如何正确地将其用作@url.action
中的参数。
我试过了
url: '@Url.Action("CreateDisease", "DiseaseLists", new {'"+diseaseID+"', '"+ assessmentID+"' })',
但它无效
$(document).ready(function () {
$('#btn-disease').click(function () {
var diseaseID = $('#DiseaseID').val();
var assessmentID = $('#AssessmentID').val();
$.ajax({
type: "POST",
dataType: "Json",
data: {diseaseID:'" + diseaseID + "',assessmentID: '" + assessmentID + "' },
url: '@Url.Action("CreateDisease", "DiseaseLists", new {//parameter here* diseaseID, assessmentID })',
success: function (f) {
if (f.Result == "success") {
alert("success!");
}
else {
alert("Disease Already Added");
}
alert("????????????????????");
}
})
})
})
答案 0 :(得分:2)
假设您的控制器是DiseaseLists(如果您问我,控制器的名称很奇怪),并且该方法是具有完全参数DiseaseID和assessmentID的CreateDisease,您可以编写类似
的内容url: '@Url.Action("CreateDisease", "DiseaseLists")',
data: {
diseaseID: diseaseID,
assessmentID: assessmentID
},
})
答案 1 :(得分:1)
您只需在url
参数中提供网址即可。请求中的数据应作为对象提供给data
的{{1}}属性。你的语法有点偏。试试这个:
$.ajax