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 -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -