3

本当に簡単な質問です。

私のレイアウトページは次のようになります

@RenderBody()
@{
  if (ViewBag.IsInternal)
  {
    //do something here
  }
}

パーシャルは次のようになります

@{
  ViewBag.IsInternal = false;
}

それは私がやるべきだと思うことをやっていますか?基本的にパーシャルで ViewBag.IsInternal が設定されていれば、その設定値をレイアウトで読み取ることができます。

4

2 に答える 2

0

Html.ViewContext.Controller.ViewBag「共有」ViewBag にアクセスするために使用できます。Pinterest ボタンを使用した場合に、「Pinterest」Javascript (ページの下部) のみを含めたい例を次に示します。

 if (Html.ViewContext.Controller.ViewBag.Pinterest == true)
 {
      <text>
         <script type="text/javascript" async defer src="//assets.pinterest.com/js/pinit.js"></script>
      </text>
 }

それからもちろん、あなたはそれを設定します

    Html.ViewContext.Controller.ViewBag.Pinterest = true;
于 2015-02-16T22:15:45.710 に答える