I have a website hosted by Nancy, I need the Razor web pages to use resource strings that will be implemented in resource files that reside in a separate library.
Is this possible?
Thank you
The main problem for this is, that you can only acess string resources from the assembly where the resouces is defined. To solve this, just add code that retrieves the text into the assembly where you want to place the text resource and call it from where you need the texts
Related
I'm looking for how to share script/style files in class library between Asp.Net Mvc projects.
I know that a lot of posts asking similar questions have been already within the stackoverflow.
But I was not sure that they are what I'm looking for.
I don't have much experience of .Net, and Asp.Net Mvc.
Just I want to achieve things like webjars that redistribute web resources as a class library.
I'm developing a class library that helps to resolve common concern in our products.
It includes razor partial views and razor layouts. They refer some stylesheet files and javascript files. So I would like to put them into the class library.
I thought to put the files into the class library as embedded resources, an tags with a url needs to be located in my web page, and a program for the url have to return the embedded resources as a content file.
What I don't know is such program has already existed, or not.
I think It is a very common issue, hence I guess that .NET has already provided things like that. But I could not find it out in the google.
I got some information regarding ScriptManager. It seems to be a component to use with Web Forms. Although I suppose to be able to port ScriptManager to Asp.Net Mvc, I don't know how to use ScriptManager anyways.
I also got some information to specify a url in script tag converted from web resource path.
It looks very easy and correct way. But I'm not sure that a url to an embedded resource in class library will be resolved.
Please tell me how to achieve it.
I'm trying to add Help to my ASP.NET MVC project.
The "help" website contains static pages about the features in my ASP.NET application.
I have added the content for this website into my ASP.NET MVC project and have added a hyperlink that will open the Help in its own window.
However, when I try to access the content, the application attempts to route to the Help controller.
How do I display the help website within my MVC application?
I am not sure you can do this within the context of an MVC application. I would consider just building an empty controller with an Index action (HelpController -> public ActionResult Index()) and just return the view name (cshtml file), shouldn't be any reason you can't rename your static html file to cshtml even if you aren't using razor (although I am not 100% sure without trying that the extension change is necessary). Also I would argue that if this ever needs more functionality you have the scaffolding in place to make non-static mods. Disabling routing within the context of an MVC solution honestly doesn't make the most logical sense. The only other choice would be if you hosted it in a different IIS site (but I don't think I would recommend that unless you have a huge help library).
Use IgnoreRoute when you configre your routing, for example, create a folder "help" in your app's root. Then load it with all your html help files. Then to ignore that route:
routes.IgnoreRoute("help");
You should then be able to access it by http://myapp.com/help/whatever.html
Is it possible to access non shared resources (web application resources XHTML / CSS ) from shared resource which is packaged as JAR file and placed inside WEB-INF/lib folder.
Eg.
App
--views
---layout
----template.xhtml
--WEB-INF
----lib
------jar1
--- ----META-INF
----------resource
------------views
--------------index.xhtml
In the above structure can index.xhtml reuse template.xhtml? I wanted to have application specific template rather than using it from shared template.
#Partlov,
As I mentioned earlier, Have solved by providing relative path starting from app context rather then from current folder.
In facelet tag declaration have used template=/views/layout/template.xhtml instead of template=layout/template.xhtml in WEB-INF/lib/jar1/Index.xhtml
#BalusC, Thanks for your note. I do agree your comment.
My Models / data silos are in a different class library which contain data annotation - Required, Max Length and some custom validation. This all works great in English however is there a way to swap the English validation message for the Spanish using a global resource file contained in the web project. The class library is used both on the web site and other components so I cannot be assured that the resource file will be in the same project.
Assuming you are talking about a .Net MVC application, I suggest you have a look at this blog post about internationalization in MVC3:
http://afana.me/post/aspnet-mvc-internationalization.aspx
For a project I am currently working on, we decided to place the resource-files in a separate project, so that we could keep all the resource-strings in one place, and then simply referring to the language-project from any other project that needs multi-lingual support.
I am very new to Silverlight development. I understand that this is client side technology therefore the paradyme is differant from that of conventional ASP.NET development. Having said that, I don't understand where my server side code is deployed.
I have a silver light \ MVC application. I am trying to read an XML document from within my 'Models' folder. The following peice of code is executed from within a class that is in the same location as the XML document, 'Models'. The load() results in a SystemIOFileNotFound exception. I noticed that when building the application the XML document is not laid down in the same location as the web project's assembly. I assume this is specific to the fact that this is a Silverlight project. Can someone tell me what I'm missing?
_xdoc = new XDocument();
_xdoc = XDocument.Load(new Uri("videos.xml",UriKind.Relative).ToString());
Edit..
The behavior I am after is the start page (silverlight) populates controls via a server side controller. ie localhost/video
Silverlight can't access your filesystem (thankfully), which is why you can't access the file. Try embedding it as a resource, or storing it in the local storage API provided by silverlight.
Assuming that your Models folder is in the Web project (i.e. not the Silverlight project), I think that your problem is unrelated to Silverlight.
The code loading the XML file assumes that the file is in the current directory, so you need to ensure this through your deployment technique.
If you are doing this in the Silverlight part, you should put the XML file in an embedded resource and access it as a stream (get it with Assembly.GetManifestResourceStream) or as a resource (a la WPF, not an embedded resource) and access it with the package part syntax.
The problem was that I was attempting to access this static resource as you would in typical ASP.net. However I found it necessary to map the path to the file using the current HTTPContext:
HttpContext.Current.Server.MapPath("~/App_Data/videos.xml");
So the above worked for me. Since this code is in the web project and not in the silverlight project I am still unclear as to why I cannot just access this resource using a relative path. This code will be executed in the context of the web server.
i.e.
XDocument.load(../App_Data/videos.xml);