Agility Modules and MVC @section Styles and Scripts

Posted by Giovanni Mattucci on June 28, 2017

MVC section styles and scripts doesn't seem to work within Agility Modules.

@section Styles {
<link href="module.css" rel="stylesheet">
}

@section Scripts {
<script type="text/javascript" src="module.js"></script>
}

Any way to get them to work?

   0 people like this question
15 30 50   per page
   
  
 
 
   
Submit
For anyone that could use what solution I came up with:

I used TempData in the Module .cshtml View to define what css and js is needed:
@{
 TempData["ModuleCss_ModuleName"] = "~/Content/module.css";   TempData["ModuleJs_ModuleName"] = "~/Content/module.js";
}


Then on the agility template, iterate through all keys what match your convention:

@section Styles {
    @foreach (string key in TempData.Keys)
    {
        if (key.Contains("ModuleCss_"))
        {
            var moduleCss = TempData[key].ToString();
            <link href="@moduleCss" rel="stylesheet">
        }
    }
}


@section Scripts {
    @foreach (string key in TempData.Keys)
    {
        if (key.Contains("ModuleJs_"))
        {
            var moduleJs = TempData[key].ToString();
            <script type="text/javascript" src="@moduleJs"></script>
        }
    }
}


Posted By: Giovanni Mattucci

Previous Next

LOGIN

Log in with your Agility username and password or
register for the site




Log In

REGISTER












Register

FORGOT PASSWORD