2

Spark View Engine は、Razor のように C# コード ブロックを処理できますか? たとえば、Razor には次のようなものがあります。

@{
   var currentController = ViewContext.RouteData.Values["controller"] as string ?? "Home";
   var currentAction = ViewContext.RouteData.Values["action"] as string ?? "Index";
   var currentPage = (currentController + "-" + currentAction ).ToLower();
}

これに相当するものは、Spark View Engine にあるでしょうか? 次に、Razor でそのようにコードを使用しています。Spark でも同じようにしたいと考えています。

<li @(currentPage == "home-index" ? "class = current" : "")>
    @Html.ActionLink("Home", "Index", "Home")
</li>
4

1 に答える 1

4

を使用し#て、行がコードのみであることを示します。

# var currentController = ViewContext.RouteData.Values["controller"] as string ?? "Home";
# var currentAction = ViewContext.RouteData.Values["action"] as string ?? "Index";
# var currentPage = (currentController + "-" + currentAction ).ToLower();

また、変数を宣言するだけの場合は、代わりに次のようにすることもできます。

<var currentController="ViewContext.RouteData.Values['controller'] as string ?? 'Home'" />

あなたの使い方は次のようになります:

<li class="current?{currentPage == "home-index"}">
    ${Html.ActionLink("Home", "Index", "Home")}
</li>
于 2013-04-08T13:31:58.087 に答える