I know that there is a way for ad C # functions inside the view and call them using the method @functions{ ... }
inside my view, but is there a way to create a general view with these functions to include controllers inside the view without copying the same line of code on each of them ? I tried using @inject
other methods inside the view _Layout
, but obviously these methods cannot be called. I also tried to create an external class like this, but I want to use views only if this is possible:
public class Functions : RazorPage<dynamic>
{
public override Task ExecuteAsync()
{
throw new NotImplementedException();
}
public string GetTabActive(string lang)
{
if (ViewBag.lang.ToString() == lang) return "active";
return "";
}
}
source
share