I need help, i can’t send parameter from ViewData in javascript to Controller, maybe because in controller using JsonResult, but I haven’t found the solution till now, is there any way to fix it ?
this my js :
var urlString2 = "@Url.Action("GetAttributeLabel", "MasterDataTemp")?modifierId=@ViewData["ModifierId"]";
$.ajax({
url: urlString2,
type: "GET",
dataType: "json",
contentType: 'application/json; charset=utf-8',
async: true,
processData: false,
cache: false,
success: function (data) {
$.each(data, function (i, item) {
dataAttributeLabel.push(item.AttributeName);
});
},
error: function (xhr) {
alert('error');
}
});
this is my controller :
public JsonResult GetAttributeLabel(Guid modifierId)
{
...........
}
The parameter always send empty guid, please help..
2
Answers
Please try like below
And at controller
Firstly, you have to avoid sending JSON data with jQuery Ajax
GET
request, if you do want to send JSON data, try with aPOST
request.Secondly, you could generate the url in
@Section
like this:And then send the request:
It works well now: