Trying to ajaxify "favorite this song".
The way I understand it, it is desirable to separate javascript from the markup completely to an external .js file. However, we require to pass id of the song along with the ajax post.
We have the following markup
<div id="favorite-song"></div>
The way I would have done it using ASP.NET ajax inside the view
<div id="favorite-song"><%= Ajax.ActionLink("Make this your favorite", "FavoriteSong", new { id = Model.ID }, new AjaxOptions {...}) %></div>
When using jQuery, I attach the onclick event to #favorite-song to fire an ajax.post request. But how do I pass the song id, or post/route values in general, to the jQuery request?
Edit: To be more specific - How do we pass that Model.ID (which is the song id) to the javascript?
Edit2: So one way to accomplish this is to add that song id as part of the markup and fetch it from DOM in jQuery roughly this way:
<div id="favorite-song"><span id="SongID-<%= Model.ID %>"></span></div>
And then when doing the AJAX post in jQuery we get that span's id, remove the 'SongID-' from the front and voila, we have the song id.
Is there alternative/better way to do this?