I want to pass the id to the controller (ASP.NET MVC 5) and get the result from the controller. I have the following code:
function LoadBook(id) { $.ajax({ url: '/Book/GetBookById' + id, type: 'get', dataType: 'json', success: function (data) { }, error: function (err) { alert("Error: " + err.responseText); } }) } Is it safe to do url: '/Book/GetBookById' + id? And if it doesn't safe, is there any way to do this?
/Book/[id]or/Book/GetBookById/[id](the second way seems redundant to me). Non-RESTful you could do /Book/GetBookById?id=[id]. That said, the VS tools could scaffold this for you automatically.