I have a jquery file that I want to reference and render in in timelime.cshtml. I am attaching the file view below. review attachment. I want reference the jquery file in the attachment below.
The name of the jquery file timeline.js.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sunny SharmaPosted Oct 11, 2013, 1:32 AM
I'm in GMT +5. It's 11:01 now.
David SmithPosted Oct 10, 2013, 3:10 PM
Sunny SharmaPosted Oct 10, 2013, 1:13 PM
Here's my skype id: sunny.programmer
David SmithPosted Oct 10, 2013, 8:58 AM
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/Timeline")
Sunny SharmaPosted Oct 10, 2013, 5:52 AM
public class BundleConfig
"~/Scripts/Timeline.js",
-------------------------------------------------------
Give it a try and let me know if it works or not.
I've skype but not able to connect to you right this moment.
Thanks,
David SmithPosted Oct 10, 2013, 4:28 AM
David SmithPosted Oct 10, 2013, 3:21 AM
Sunny SharmaPosted Oct 10, 2013, 1:25 AM
OR
"
My Answer:
Bundling the Script in one bundle gives you freedom to use them wherever you need it and not where you don't.
Please note, that if you create a bundle with the name that is already created, the bundle information would get over-written. What I mean is, If I have added a Script Bundle with name "~/bundles/jquery", which contains jquery-1.9.1.min.js and jquery.scrollTo-1.4.1.js, two files:
AND,
I'm trying to create another one with same name, it gets over-written:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
// here it contains only one file - jquery.scrollTo-1.4.1.js.
So now if I try to render this bundle: ~/bundles/jquery, using this statement: @Scripts.Render("~/bundles/jquery"), it will render only a single file jquery.scrollTo-1.4.1.js because this is what we have declared in the last bundle for said name.
Please check if you're adding two bundles with same name. Bundles provide you the flexibility of rendering only required files hence decreasing the bandwidth and increasing the speed, like, if I need jquery UI on any View, I'll render a bundle that contains jquery-ui... .js, otherwise I won't.
Thanks.
David SmithPosted Oct 9, 2013, 8:45 PM
or
Sunny SharmaPosted Oct 9, 2013, 2:17 PM
What I meant, If timeline.js file has any dependency to this jquery.scrollTo-1.4.1.min.js then do add this to the bundle, otherwise you don't need to.
You can share your project if still have any issues and I'll sort it out.
Thanks.
David SmithPosted Oct 9, 2013, 2:03 PM
Sunny SharmaPosted Oct 9, 2013, 1:54 PM
Apart of that, modify this line of code:
---------------------------------------------------
" @Model.LoadMoreUrl "')" href="javascript:void(0)">
More
as
More
(Remove the double quotes around @Model.LoadMoreUrl)
HTH :)
David SmithPosted Oct 9, 2013, 11:26 AM
David SmithPosted Oct 9, 2013, 10:53 AM
David SmithPosted Oct 9, 2013, 10:48 AM
-The timeline.js is located in the script folder.
-By default for the ASP MVC4 template the _layout.cshtml has the @Scripts.Render("~bundles/jquery") at the bottom of the page after the footer.
-I did not add @Scripts.Render("~bundles/timeline") to the _layout.cshtml, because you said if i wanted the timeline.js file to be render on every page just add it to the bundle. I did just that. Review below.
Review attachments below and look at every file.
Sunny SharmaPosted Oct 9, 2013, 5:53 AM
Not to worry about, I'll help you with that.
I assume in my previous post that timescript.js file is present inside Scripts folder. If not, then please move it and try again. If yes, please try to check in the View Source of rendered html if "timeline.js" is being rendered. Just try to find "timeline.js". If it's in there then it is being rendered otherwise not.
If it is being rendered and it's not working as expected then there must me some problem within your timeline.js file codes, suggest you to check that.
If it's not being rendered, check your master layout _Layout.cshtml if it has the snippet at the bottom or top to render the defined script bundle:
@Scripts.Render("~/bundles/timeline")
HTH :)
David SmithPosted Oct 9, 2013, 5:34 AM
I changed the second input parameter.
From:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.10.2.min.js",
"~/Scripts/timeline.js",
));
To:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.9.1.min.js",
"~/Scripts/timeline.js",
));
However I am still troubleshooting why my timeline feature is not working yet. I wonder if the .js file is being rendered.
Sunny SharmaPosted Oct 9, 2013, 3:22 AM
The easiest way is to use the bundling feature that comes with MVC 4.
Open BundleConfig.cs file under App_Start, find this pattern and modify:
------------------------------------------------------------------------
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.10.2.min.js",
"~/Scripts/timeline.js",
));
------------------------------------------------------------------------
That's it. Now it will be rendered automatically wherever you've this snippet in view:
@Scripts.Render("~/bundles/jquery")
basically above line lies in _Layout.cshtml so that jquery file is rendered in each derived page.
Alternatively, if you want to refer this file to any specific page only, then create a script bundle and refer in those pages, like:
Your new script bundle:
-----------------------------------------------------------------------
bundles.Add(new ScriptBundle("~/bundles/timeline").Include(
"~/Scripts/timeline.js",
));
-----------------------------------------------------------------------
Now put this snippet to render this bundle in any view like:
@Scripts.Render("~/bundles/timeline")
Hope you got the point.
Happy Coding :)