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

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -