I have the following DIR structure:
Public
--mobile
----Views
------UK
--------Recipes
----------ViewRecipePlain.cshtml // pull this
--mobilePublic
----Views
------UK
--------Recipes
----------ViewRecipe.cshtml // into this
I want to call ViewRecipePlain.cshtml from within ViewRecipe.cshtml
Inside ViewRecipe.cshtml I'm trying:
#Html.Partial("../../../../mobile/Views/UK/Recipes/ViewRecipePlain")
But am getting the error:
Cannot use a leading .. to exit above the top directory.
Is there another way to do this?
UPDATE
I also tried:
#Html.Partial("~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml")
But get the following error:
The partial view '~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml' was not found or no view engine supports the searched locations.
The following locations were searched:
~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml
Have also update DIR structure to be more accurate if it makes a difference but doubt it does.
You can just use the absolute path of the view:
#Html.Partial("~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml")
Related
After deploying a new version of a website the browser loads everything from its cache from the old webpage until a hard, force refresh is done.
In ASP.NET MVC if the file becomes in Bundle, it handled by Optimization framework. a version added to your file link, and if a change occurs in your bundle's file a new token generate. follow below code :
for example, js file name is: datatables
when you put it in a bundle with the same name, you will see the
datatables?v=anY9_bo7KitrGnXQr8ITP3ylmhQe9NDzSjgLpLQWQFE1
as a file name.
change datatables and watch again the name of the file in the browser, surely it will change:
datatables?v=r8yhQBxKyDgrOGyqr1ndtdG92Ije09nqTY7yogrOSTk1
But there's two questions:
What we can do if our file wasn't in Bundle?
Is a way to force the browser to refresh cache?
we have one solution with some different way for implementation. we use above solution for it.
datatables?v=1
we can handle the version of the file, it's mean that every time that we change our file, change the version of it too. but it's not a suitable way.
another way used Guide, it wasn't suitable too, because each time it fetches the file and doesn't use from the browser cache.
datatables?v=Guid.NewGuid()
The last way that is the best Way is :
when file change occur , change version too. check follow code :
<script src="~/scripts/main.js?v=#File.GetLastWriteTime(Server.MapPath("/scripts/main.js")).ToString("yyyyMMddHHmmss")"></script>
by this way, when you change the file, LastWriteTime change too, so the version of the file will change and in the next when you open the browser, it detects a new file and fetch it.
Assuming you cannot use bundling for some reason, the solution suggested by the original poster is good enough, however it's better to put the logic inside a helper method.
It makes the code testable, it helps to change the logic without changing .cshtml , and also helps to not repeat the filename twice. Then you can have have a much cleaner code:
<script src="#Url.ContentWithVersion("~/scripts/main.js")"></script>
To do so, you can add ContentWithVersion extension method to the existing UrlHelper:
using System;
using System.IO;
using System.Web;
using System.Web.Mvc;
public static class UrlHelperExtensions
{
public static string ContentWithVersion(this UrlHelper urlHelper, string path)
{
if (urlHelper == null)
throw new ArgumentNullException(nameof(urlHelper));
var result = urlHelper.Content(path);
var file = HttpContext.Current.Server.MapPath(path);
if (File.Exists(file))
result += $"?v={File.GetLastWriteTime(file).ToString("yyyyMMddHHmmss")}";
return result;
}
}
I'm currently creating an MVC ASP.NET application in which multiple widgets are loaded from a different location. I have most of the logic down, but I get stuck trying to load the widgets from a differnt location than the original one.
Everything was working when I used this
foreach (WidgetPrototype.Models.Widget widget in Model)
{
<blockquote style="border-style: outset">
#Html.Partial(widget.Name)
</blockquote>
}
But when I moved the files to test loading views from a different location, changing my code to
foreach (WidgetPrototype.Models.Widget widget in Model)
{
<blockquote style="border-style: outset">
#Html.Partial(#"D:\" + widget.Name + ".cshtml")
</blockquote>
}
It stopped working, and gave the error that the view could not be found, with the message:
[InvalidOperationException: The partial view 'D:\Clock.cshtml' was not
found or no view engine supports the searched locations. The following
locations were searched:
~/Views/Widgets/D:\Clock.cshtml.aspx
~/Views/Widgets/D:\Clock.cshtml.ascx
~/Views/Shared/D:\Clock.cshtml.aspx
~/Views/Shared/D:\Clock.cshtml.ascx
~/Views/Widgets/D:\Clock.cshtml.cshtml
~/Views/Widgets/D:\Clock.cshtml.vbhtml
~/Views/Shared/D:\Clock.cshtml.cshtml
~/Views/Shared/D:\Clock.cshtml.vbhtml]
So apparently it's still trying to find the files on a relative path in the project.
Is there a way to force it to just use the full path?
Have you tried specifying the relative path?
E.g.
#Html.Partial("../MyViews/_PartialView", Model) ?
Would also recommend using #Html.RenderPartial as it works faster.
I'm trying to invoke an image with infobox and infoboxImage. Here is what I have....
|image = {{#invoke:InfoboxImage|InfoboxImage|image={{{image|}}}|size={{{image_size|}}}|upright= {{{image_upright|1}}}|alt={{{alt|}}}}}
And I get the following error on my index.php?title=Module:InfoboxImage&action=submit#mw-ce-l1 page
Script error: Lua error at line 1: unexpected symbol near '|'.
What do I need to do to get this working?
Here is my LocalSettings.php for Scribunto:
require_once "$IP/extensions/Scribunto/Scribunto.php";
#$wgScribuntoDefaultEngine = "luastandalon"';
So you're adding template syntax like {{{image|}}} in a module page? Why?
I doubt you really need to handle such a Lua module for your wiki. However, if you really want to copy the Lua-powered infobox templates of other wikis, make sure you import them with Special:Import and select the recursive import checkbox.
Hopefully you'll then have all the modules you need without fiddling with them.
I'm currently trying to load and use the Gephi Toolkit from within a .Net 4 C# website.
I have a version of the toolkit jar file compiled against the IKVM virtual machine, which works as expected from a command line application using the following code:
var controller = (ProjectController)Lookup.getDefault().lookup(typeof(ProjectController));
controller.closeCurrentProject();
controller.newProject();
var project = controller.getCurrentProject();
var workspace = controller.getCurrentWorkspace();
The three instances are correctly instantiated in a form similar to org.gephi.project.impl.ProjectControllerImpl#8ddb93.
If however I run the exact same code, with the exact same using statements & references, the very first line loading the ProjectController instance returns null.
I have tried a couple of solutions
Firstly, I have tried ignoring the Lookup.getDefault().lookup(type) call, instead trying to create my own instances:
var controller = new ProjectControllerImpl();
controller.closeCurrentProject();
controller.newProject();
var project = controller.getCurrentProject();
var workspace = controller.getCurrentWorkspace();
This fails at the line controller.newProject();, I think because internally (using reflector) the same Lookup.getDefault().lookup(type) is used in a constructor, returns null and then throws an exception.
Secondly, from here: Lookup in Jython (and Gephi) I have tried to set the %CLASSPATH% to the location of both the toolkit JAR and DLL files.
Is there a reason why the Lookup.getDefault().lookup(type) would not work in a web environment? I'm not a Java developer, so I am a bit out of my depth with the Java side of this.
I would have thought it possible to create all of the instances myself, but haven't been able to find a way to do so.
I also cannot find a way of seeing why the ProjectController load returned null. No exception is thrown, and unless I'm being very dumb, there doesn't appear to be a method to see the result of the attempted load.
Update - Answer
Based on the answer from Jeroen Frijters, I resolved the issue like this:
public class Global : System.Web.HttpApplication
{
public Global()
{
var assembly = Assembly.LoadFrom(Path.Combine(root, "gephi-toolkit.dll"));
var acl = new AssemblyClassLoader(assembly);
java.lang.Thread.currentThread().setContextClassLoader(new MySystemClassLoader(acl));
}
}
internal class MySystemClassLoader : ClassLoader
{
public MySystemClassLoader(ClassLoader parent)
: base(new AppDomainAssemblyClassLoader(typeof(MySystemClassLoader).Assembly))
{ }
}
The code ikvm.runtime.Startup.addBootClassPathAssemby() didn't seem to work for me, but from the provided link, I was able to find a solution that seems to work in all instances.
This is a Java class loader issue. In a command line app your main executable functions as the system class loader and knows how to load assembly dependencies, but in a web process there is no main executable so that system class loader doesn't know how to load anything useful.
One of the solutions is to call ikvm.runtime.Startup.addBootClassPathAssemby() to add the relevant assemblies to the boot class loader.
For more on IKVM class loading issues see http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=ClassLoader
I am trying to access my local resources file in my code-behind. I did some googling since I was unsure of how to do it and found this:
oContent.Text = HttpContext.GetLocalResourceObject("NonSupport").ToString();
However, I get an error saying that it needs at least two parameters: VirtualPath and ResourceKey. There is a third, CultureInfo but that one is optional. When I put this in as my virtual path:
HttpContext.GetLocalResourceObject("App_LocalResources/ExpandableListView.aspx.resx", "NonSupport").ToString();
I get the following compiler error message:
The relative virtual path 'App_LocalResources/ExpandableListView.aspx.resx' is not allowed here.
I must be doing something wrong with this since my searches (and some posts I found on here) say all I need to do is call the resource key.
Any thoughts? Thanks!
Did you put a resource file with the name (your aspx web page).aspx.resx into a App_LocalResource folder underneath the path where your ASPX page lives??
Furthermore, just simply call the GetLocalResourceObject method on your current page:
oContent.Text = GetLocalResourceObject("NonSupport").ToString();
No need to use HttpContext for that - the method is defined on the Page class.
Marc