how to read data send from renderpartial
in my index.aspx page i have something like:
<% int tid = Convert.ToInt32(ViewData["TemplateId"]);
Html.RenderPartial("/Views/Templates/MyMod开发者_如何学运维ule.aspx", tid); %>
how to read tid in MyModule.aspx using javascript pls help
thanx
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.
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.
精彩评论