私のindex.aspxページには次のようなものがあります:
<% int tid = Convert.ToInt32(ViewData["TemplateId"]);
Html.RenderPartial("/Views/Templates/MyModule.aspx", tid); %>
JavaScript を使用して MyModule.aspx の tid を読み取る方法 pls help
ありがとう
私のindex.aspxページには次のようなものがあります:
<% int tid = Convert.ToInt32(ViewData["TemplateId"]);
Html.RenderPartial("/Views/Templates/MyModule.aspx", tid); %>
JavaScript を使用して MyModule.aspx の tid を読み取る方法 pls help
ありがとう
@Stephenの答えが好きです。
もう 1 つの方法は、次のように jQuery を使用することです。
Html.RenderPartial("/Views/Templates/MyModule.aspx", tid, new { @class='TID'});
次にjQuery
var tid = $('.TID').val();
モデルの値ではなく、TID がクラス名であることを示すために、tid を大文字にしました。
asp.netにtidをjavascript変数として書き出すだけです
<% int tid = Convert.ToInt32(ViewData["TemplateId"]);
Html.RenderPartial("/Views/Templates/MyModule.aspx", tid); %>
<script type="text/javascript">
var tid = <%= tid.ToString() %>
</script>
これを HTML の head に出力したい場合があります。