[英]Parameter not getting passed in AJAX call
I am using the following code 我正在使用以下代码
function test()
{
GetAttributesForSelectedControlType('Phone Number');
}
function GetAttributesForSelectedControlType(questionType) {
alert(questionType);
$.ajax({
url: '/Wizards/GetAttributesForSelectedControlType/' + questionType,
type: "GET",
contentType: "application/json",
success: function (result) {
alert('success');
}
});
}
PLEASE NOTE: QUESTIONTYPE is a STRING value and not any type.. 请注意:QUESTIONTYPE是STRING值,而不是任何类型。
The issue is that in the controller, I m getting a hit on "GetAttributesForSelectedControlType"
function but the parameter value is coming null. 问题是在控制器中,我遇到了
"GetAttributesForSelectedControlType"
函数,但参数值"GetAttributesForSelectedControlType"
空。 I am sending string in questionType
. 我在
questionType
发送字符串。 any ideas on this? 有什么想法吗?
function GetAttributesForSelectedControlType(questionType) {
alert(questionType);
$.ajax({
url: '/Wizards/GetAttributesForSelectedControlType',
contentType: "application/json",
data: {
questionType: questionType
},
success: function (result) {
alert('success');
}
});
}
如果您希望将问题类型作为参数传递,则应使用data:{qType:questionType}
它将填充函数GetAttributesForSelectedControlType
的参数qType。
Try: 尝试:
function GetAttributesForSelectedControlType(questionType) {
$.get('/Wizards/GetAttributesForSelectedControlType', {questionType: questionType })
.done(function(data) {
alert('success');
});
}
You need to pass in questionType
as a data. 您需要将
questionType
作为数据传递。 Alternatively you could just add the follwoing into your existing ajax call. 或者,您可以只将以下内容添加到现有的ajax调用中。
data: {questionType: questionType }
This will work with the following action: 这将通过以下操作起作用:
public ActionResult GetAttributesForSelectedControlType(string questionType)
{
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.