views:

72

answers:

2

in my index.aspx page i have something like:

  <% int tid = Convert.ToInt32(ViewData["TemplateId"]);
  Html.RenderPartial("/Views/Templates/MyModule.aspx", tid); %>

how to read tid in MyModule.aspx using javascript pls help

thanx

+1  A: 

Just to have asp.net write the tid out as a javascript variable

<% int tid = Convert.ToInt32(ViewData["TemplateId"]);
  Html.RenderPartial("/Views/Templates/MyModule.aspx", tid); %>

<script type="text/javascript">
    var tid = <%= tid.ToString() %>
</script>

You may want to output this in the head of your HTML.

Stephen M. Redd
Yep this works, you can also set a hidden input with the value, if you don't like the idea of cross language scripting.
Omar
+1  A: 

I like @Stephen's answer.

Another alternative is to use jQuery like this;

Html.RenderPartial("/Views/Templates/MyModule.aspx", tid, new { @class='TID'});

then the jQuery

var tid = $('.TID').val();

I uppercased tid to indicate that TID is the class name as opposed to the value from your model.

griegs