How jquery script file gets the ID value of Asp.Net MVC 3's route data? -



How jquery script file gets the ID value of Asp.Net MVC 3's route data? -

the url http://localhost:52974/app/detail/23432. know next code can id (23432) , can used in javascript code embedded in cshtml file.

@viewcontext.routedata.values["id"]

however, have external jquery script file handle document.ready function. next approach not work because it's not cshtml file. what's best approach mvc route id value besides using javascript parse url?

$(document).ready(function () { var id = @viewcontext.routedata.values["id"];

i view render out script tag invoke phone call init function in external js passing id param.

view:

<script> app.init('@viewcontext.routedata.values["id"]'); </script>

external js:

var app = {}; (function(app){ var _id; app.init = function(id){ _id = id; } })(app);

jquery asp.net-mvc-3

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -