1

私のindex.aspxページには次のようなものがあります:

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

JavaScript を使用して MyModule.aspx の tid を読み取る方法 pls help

ありがとう

4

2 に答える 2

1

@Stephenの答えが好きです。

もう 1 つの方法は、次のように jQuery を使用することです。

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

次にjQuery

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

モデルの値ではなく、TID がクラス名であることを示すために、tid を大文字にしました。

于 2009-12-11T04:13:33.367 に答える
1

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 に出力したい場合があります。

于 2009-12-10T10:46:51.217 に答える