I have the folliwng JSON request code on an ASP.NET MVC web application:
var userID = 'id=' + $('#namesList').val();
$.getJSON('/Person/GetPerson/', userID, function(data) {
$('#collar').text(data.collarNumber);
$('#name').text(data.Name);
$('#email').text(data.EmailAddress);
});
This creates a request such as: http://localhost:48610/Person/GetPerson/?id=6. Why is there a question mark in there? I get the server error The parameters dictionary contains a null entry for parameter ‘id’ of non-nullable type ‘System.Int32’….
If I make the request manually without the question mark it works fine.
Parameters in the URL go, by definition, after an “?”. In MVC, route parameters are not actually parameters (for the web browser), but part of the path. As such, the correct code would be:
Replace null with a list of parameters when your controller actually accepts extra values not in the MVC route. Ex, your controller might be:
and you would call it like this: