asp mvc 6 include ckeditor via bower - asp.net-mvc

I've included CKEditor (4.5.3) via bower.js, but on the View, I just can't figure out how to make it work.
I'm working on a default MVC6 project template and I haven't changed any gulp.js paths.
I'm guessing I'm missing something there, since It wants to join scripts from paths.webroot + "js/**/*.js";
and the CKEditor is located inside wwwroot/lib/ckeditor
Everything works fine if I add <script src="/lib/ckeditor/ckeditor.js"></script> on the View...
But that's missing the point, since gulp should take care of it.
Can anyone please help?

Related

C# MVC5 Upgrade broke Javascript loading

Just upgraded a very old project from MVC 4 to 5 and now after the upgrade the Razor Partial views which were working fine no longer work.
By this I mean that in the partial views there is a Script file that is called at the bottom:
<script src="~/Scripts/simAvail.js" type="text/javascript"></script>
And this was loading the JS and in that file some JQuery added CSS etc as needed to the elements on the page. However after the upgrade this JS file is no longer loaded and I use this method on many pages in the project so wondered if anyone knows the reason why.
The data in the Partial view is loaded and displayed but all the styling and reading/posting of the changes via Ajax is no longer there as this is what the JS file adds to the page.
Thanks
I Managed to fix this it turns out that when the upgrade to MVC5 happened part of the process as detailed on the MS instructions was to re-install all the Nuget's. This part actually installed the latest versions of all the JS packages like JQuery/Knockout etc without me noticing.
This then caused there to be two versions of everything being loaded and thus caused the issue. SO I deleted the old version of the JS packages and back running.

Nested application ignores bundles

I'm trying to run my ASP.NET MVC 5.2.3.0 application as nested application so that I can access it as a subfolder, like http://example.com/my-application.
I've added it to an existing application by choosing Add Application a chosen separate application pool.
When I run my-application on its own URL it works fine however when I try to run it as http://example.com/my-application it refuses to render bundles, neither style nor js.
What I have tried so far:
I have tried to enable and disable bundling and minification. When it's disabled Styles.Render adds nothing to markup. When it's enabled invalid link to bundle is added to markup, for example <link href="/calc/bundles/styles/mainlayout?v=" rel="stylesheet"/> and the link returns empty document.
I have tried to put my-application to empty website to ensure no side effects inherited. No difference here.
I have tried to put brand new application side by side with my-application and bundling worked fine there so it must be something wrong with my application and I can not find what exactly.
I have tried to ILSpy System.Web.Optimization code but couldn't find any help there.
I have failed to debug System.Web.Optimization as my VS just hung.
I didn't find any conflicting routes with my-application address.
If anyone faced the same issue then any advice appreciated.
Thanks.
UPDATE: I found what causes the issue. We intensively use T4MVC and we use it for bundles configuration as well. So our bundle declaration looks something like:
bundles.Add(new ScriptBundle("~/bundles/scripts")
.Include("~" + Links.Scripts.Script1_js, "~" + Links.Scripts.Script2_js));
And "~" + Links.Scripts.Script1_js for nested application gives me ~/my-application/scripts/script1.js while VirtualPathProvider from inside Include method expects it to be ~/scripts/script1.js.
So the question transforms into: does anyone know how to prevent T4MVC from adding nested application path onto static files links so that application isn't aware of being nested? I bet #David Ebbo knows how to achieve this :)

MVC Tag helpers not working

I have an issue with tag helpers.
All I want to do is create a form that posts data to the controller - basic enough I thought but it doesnt work in my project.
I create a brand new asp.net core web application with default setup and it works there but my project refuses to recognise the tags and act accordingly.
Notably the markup doesnt highlight the same or provide info when hovered over so some ref or something fundamental is missing, can anyone advise.
*Default project working with correct highlights
*My project - not highlighting the code right or working.
Project.json is the exact same so I have no idea whats missing.
FOUND IT!
Microsoft like to change things. So, MVC 6 (asp.net core ...etc) can make use of a _ViewImports.cshtml file in the views folder (feel free to add it yourself if you like me made a project before this existed).
This acts like global import file, and to make the tag helpers available in all your views, you need to add reference here.
Mine now looks like this:
#using Mobile.Models
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
And boom - tags look correct and its work as expected.
You will also face this issue when you create a new Area in the asp.net core MVC project, to resolve it copy ~/Views/_ViewImports.cshtml to ~/AreaName/Views/_ViewImports.cshtml
Make sure that you MUST specify the assembly name and not the namespace.
That was my mistake.

My js in the Scripts folder are not being loaded in my MVC4 app

I have 2 scripts. One is in a Folder called ItemMenu in the root and the other is in the Scripts folder that is also in the root.
The script in the Scripts folder is never loaded, but the ItemMenu one it. They are both included in a script tag the same way on the client.
Here is the HTML render of the scripts.
<script src="/Scripts/article_layout1.js"></script>
<script src="/ItemMenu/itemMenu.js"></script>
If, I use the full URL it will work - but this won't work long term.
It's not making any sense to me.
I have confirmed the locations of these and "/Scripts/article_layout1.js" can be accessed by navigating directly to the URL. I have confirmed the spelling and folder names.
Does anyone have any idea here? This is going to make me crazy maybe.

Unable to Bundle JQuery Mobile 1.2 in ASP.NET MVC 4 app

I'm working on an ASP.NET MVC 4 app. This app leverages bundling to improve performance. Previously, the app was using jquery.mobile-1.1.0.js. Everything worked fine. However, I've upgraded to JQuery Mobile 1.2 and when I load my screen, I always see a wait spinner. I've pinpointed it to the fact that both the standard and the minified versions are being referenced. When I look in my view-source after the page is loaded, I see the following at the top:
<script src="/Scripts/jquery.mobile-1.2.0.js"></script>
<script src="/Scripts/jquery.mobile-1.2.0.min.js"></script>
From what I can tell, this was generated from the following in my ASP.NET MVC .cshtml file
#Scripts.Render("~/bundles/jquerymobile")
In my BundleConfig.cs file, I have the following definition:
bundles.Add(new ScriptBundle("~/bundles/jquerymobile").Include("~/Scripts/jquery.mobile*"));
Essentially, I want to use the normal version when the debug="true" flag is set in my web.config compilation setting. However, when debug="false", I want to use the minified version. What am I doing wrong?
Thank you
This should happen automatically for you already (assuing the fileextensionreplacement lists still have the default "min" entry for when optimizations are enabled).
As a workaround, you could try this instead which should also work:
.Include("~/Scripts/jquery.mobile-{version}.js"));
This basically is similar to your * except it will regex match for version strings. Note, both this and what you have require that you only have the latest jquery in your Scripts folder, if you still have the 1.1 version there, you will end up with both versions in your page.

Resources