Embedded views and resources (mvc) - model-view-controller

I've embedded several views in a library so that I can re-use across projects using this method which works OK:
http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/
But one view usings a Javascript file. I've tried marking this as an embedded resource and adding it AssemblyInfo.cs and then referencing this resource using
<%= ClientScript.GetWebResourceUrl(this.GetType(), "FullPath.FileName.js")%>
This is literally displaying this output in the view
WebResource.axd?d=nUxqfqAUQLabLU54W
I think this is because Im trying to refer to an embedded resource from an embedded resource.
Help appreciated as Im going round in circles..
Steve

The problem here was with my call to GetWebResourceUrl. I've changed the format to that below and it works fine :)
<script src="<%= ClientScript.GetWebResourceUrl(typeof(Opal.Web.Shared.AClassInMyAssembly), "FullPath.FileName.js")%>" type="text/javascript"></script>
So Ive contained the call in a script tag and changed the type parameter.

Related

how to solve the kwidget not defined in kaltura

I have modified my modified my html5 library to point my kaltura server. Now I am able to play videos as static html webpage. but I tried in my project which is developed using php, it doesn't play the videos in even PC's too.
It says kwidget is not defined.
I used the kWidget embed code. But it s not happened in auto embed or flash embed.
But I read that kwidget is good to reduce the page load timings
If you are using any MVC, you need to add the mwEmbedLoader script in the service or controller's head. I think you used the kwidget code in view sector and not add your script in controller page. you need to add your script in all the pages wherever the player function calls as below.
You can add that in couple of ways.
<script src="http://youkalturaserver.example.com/p/partnerId/sp/partnerId+00/embedIframeJs/uiconf_id/11170264/partner_id/partnerId"></script>
<script type="text/javascript" src="http://youkalturaserver.example.com/html5/html5lib/v2.69.7/mwEmbedLoader.php"></script>
replace v2.6.7 with current release version:
https://github.com/kaltura/mwEmbed/releases
It will solve this error

Grails won't load changes done in static resources (except when restarting)

I have an annoying problem with my new grails app. I'm trying to mock up a design for a site that I will be making but whenever I do changes in my css it won't affect the running application. No matter how big changes I do I have to stop the application and then run it again.
This is very frustrating, I've turned of cache in Chrome and even if I go to the specific document the resource is still the old. What can I do to solve this problem? I can make changes in my gsp files and the changes will appear but not in my css.
I am currently loading the resource within a layout file like this:
<link rel="stylesheet" href="${resource(dir: 'css', file: 'app.css')}" type="text/css">
If you need me to provide any more information, please just ask. I am using grails 2.2.0.
Add this to your Config.groovy (probably just for development)
grails.resources.debug = true
Read the docs for more info.
It looks like Gregg's answer doesn't work for 1.3.7 (maybe that is something added in 2.x?). A method I found that makes quick CSS updates possible is to include a separate GSP as a template in the page header.
That is, create a file called "_css.gsp" (underscore prefix is required) in the same directory as your view files, fill it with standard css surrounded by html style tags, and then include the following in your layout header or page:
<g:render template="css" />
With that in place, the content of _css.gsp is injected into the page. And I can make changes to _css.gsp and they are immediately reflected after page refresh without having to restart Grails. Hope this helps someone in Grails pre-2.x!

Can I create a controller in a common assembly which will be accessible by any assmbly which references it?

I have a common assembly where I put a lot of my helper functions etc. I want to create a common EmbeddedResourceController (kind of like WebResource.axd was for WebForms) which all my HTML helpers can use to embed and display their scripts and styles. The problem is, I need to be able to create an include path from my HTML helper code in a project agnostic way (ie without knowing any of the routing/controller rules in that project).
Ideally, I want to create an include like <script type="text/javascript" src="/EmbeddedResource/myJsScript.js"></script> from the helper code and have it work in every project that uses my common dll.
If I understand your question correctly, you can just use this EmbeddedResource controller as a base for a controller in each of your projects:
EmbeddedResourceController : EmbeddedResourceBase
Where EmbeddedResourceBase lives in your common dll
Perhaps you can use an HTML helper extension. Take a look at Mr Bell's answer in the following question Populate a Razor Section From a Partial

MVC3 Using or Finding the ApplicationPath inside of the _Layout.cshtml page

I have a C#.Net web app and the pathing is different from my local box to the dev box. My local url is http://localhost:<port>/Proposal/Edit. However, on the dev server, it is http://{MydevServer}/dev/app/Proposal/Edit]. So, this causes issues with the Style Sheet and navigation links, etc. I know I can grab the ApplicationPath inside all the Controllers and set a variable whic the pathed elements can use. But that seems like too much work for this issue. Any ideas on how to solve this? Is it possible to get the ApplicaionPath in the _Layout.cshhml file? Is ther a better idea?
You can call Href("~/") in any Razor page to get the full client path to your application root.
you should be using the Url.Action and Url.Content helper methods for generating your links and src attributes. then you'll never need to worry about it.

Why do I need a script loader?

People are telling me that I need a script loading for web app, but I already have <script /> and <link /> tags already, can anyone tell me when I should use a script or resource loader? and What is the load you recommend.
I'm assuming they are referring to loading and executing javascript files as and when needed, to reduce the initial load times of pages by not loading all your scripts in the head section of the html.
Not totally sure if thats what your getting out, could you give more information on the situation? does your web app have a large number of javascript tags?
I think the requirement of the scripts loader is for multiple <script src=""> tags in the html page, one of more of the scripts have the loading order required, like: the jquery.js must be loaded before the jquery-plugin.js. Another case is the scripts which will be loaded are different in different client devices, like the javascript run for desktop client will be different than the javascript run in the touch pad
When you are working on a single-page application with a lot of dependencies between JS files.

Resources