chamara
chamara

Reputation: 12709

Remove .js file from specific pages

I have an ASP.NET MVC web application designed with a layout page and few child pages. i have applied all .js files in my layout.chtml.

i want to remove links to some .js files in some child pages.

for example i have below in my layout.chtml

<script src="@Url.Content("~/Content/acebs/assets/js/jquery.mobile.custom.min.js")"></script>

my child page is as follows.

@model FeedBackDashBord.Models.ChatLIST
@{
    ViewBag.Title = "Chat Settings";
    Layout = "~/Views/Shared/layout.cshtml";
}

how can i remove the link to jquery.mobile.custom.min.js from my child page?

Upvotes: 0

Views: 1488

Answers (1)

SynXsiS
SynXsiS

Reputation: 1898

You could use an optional section on your layout page. On the specific pages where you don't wish to include the script you would need to provide a value for this section - even if it's just an empty block.

@if (IsSectionDefined("OptionalContent")) { 
    @RenderSection("OptionalContent")
}
else { 
    <script src="@Url.Content("~/Content/acebs/assets/js/jquery.mobile.custom.min.js")"></script>
}

More details can be found here: http://blogs.msdn.com/b/marcinon/archive/2010/12/08/optional-razor-sections-with-default-content.aspx

Upvotes: 1

Related Questions