I've created a class library in which I store my resource files for my asp.net mvc4 localization. I've been following the same folder structure as my Views.
I'm ending up having to reference strings such as:
#Resource.QuoteArea.Quote.Auto.DriverInfo
That is very long and tedious to type. Plus it makes my Views hard to read. Is there a better (neater) way for doing localization in mvc 4 ? Perhaps using a third-party library ? I already use mvccontrib for my model localization, so that's sorted. However for non-model related things, I'm facing the aforementioned issue.
You can change the resource namespace in the resource properties, to make it shorter. This blog post was very helpful for me, and will be for you to.
http://adamyan.blogspot.co.uk/2010/02/aspnet-mvc-2-localization-complete.html
Related
Why are models not in a separate Model folder in the api template? The original template comes with WeatherForecast.cs as a separate file just by itself.
Are we not supposed to have a folder for models?
In this template you actually get minimal settings for ASP.NET project as program.cs and startup.cs with minimum configuration.
Then you choose how your folders will be located, depending on what you are going to do. If you want to make a couple of controllers with couple of methods, and you are not going to expand the functionality, you can write all the functionality of your program there and create two folders: controllers and models. In the case where you need to build a large application with a lot of logic, you need to use common web application architectures.
You can read this article and find a right direction for searching, but it is more than just "separate file and folders", this is a very big topic for thought.
I need some assistance in creating a simple html page and locate it in the server.
Since I couldnt find it in the doc I tried to put a index2.html file in the /public library and when I tried to get receive it using
http://127.0.0.1:3000/index2.html
or
http://127.0.0.1:3000/public/index2.html
and receiver
ActionController::RoutingError (No route matches [GET] "/public/index2.html"):
how do I get the html from the server
how di I make it the default.
Thanks.
EDIT : thanks for your answers. I am looking for the simplest way to work. in many tutorials it says you can put it in the public folder and thats it. This will same me useless controllers.
You can do that in several ways : the more obvious would be to have an action in one of your controller (or a new one, whatever) that does nothing (except render the view), and add a route to it. There is other ways to achieve this too, with more adapted tools. I never used any of them, so might want to google it (static page rails), but I know one of them is a gem called High Voltage. Hope this serves you well.
I think you might have mis-understood Rails...
I have never used it but I think I can probably help you with your answer. Rails is the most popular MVC framework for the language Ruby, hence 'Ruby on Rails'. Here is a link to the MVC framework this may help you understand it:
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
With the MVC framework you can't 'get' a file directly through the URL. You have to get it through the routing engine. Usually you do this through a Controller which renders a view, typically, from a model.
It's difficult to explain if you don't understand how the MVC framework works but once you have an understanding you should be able to develop web applications very rapidly.
Have a look here for creating your first rails app:
http://guides.rubyonrails.org/getting_started.html
I am trying to implement a global exception handler in Asp.NET MVC 4 beta. As I understand it I am supposed to implement an IExceptionFilter and add that to the filters collection. However I was unable to make it work when using the System.Web.Mvc.IExceptionFilter. Am I supposed to use that one, or is the System.Web.Http.Filters.IExceptionFilter (and related classes) the ones I should be using?
Asking another way:
Should I be adding filters to the GlobalConfiguration.Configuration.Filters or GlobalFilters.Filters?
System.Web.Http namespace completely belongs to ASP.NET Web API framework, not ASP.NET MVC.
As for the registration point, you need to add them into GlobalFilters.Filters collection.
So after getting some pointers from #tugberk, I realize my mistake. I was basically asking for the wrong thing. What I wanted was to be able to add filters for an ASP.NET Web API service, not add them for an mvc application.
I made this error thinking they were one and the same. I guess I must have read som of what was said about moving these things together the wrong way.
In any case. I should be using the System.Web.Http namespace for my case, which means adding to the GlobalConfiguration.Configuration.Filters collection.
I found a rather nice weblog showing a basic implementation of some of what I want to accomplish. Maybe it can help somebody else.
I read Scott Gu's article about built-in support for bundling and minification in ASP .NET 4.5.
However there's no mention of embedded resources, which is a pity.
In the past I've been using a Codeplex project called Client Dependency Framework which supported embedded resources.
Seems like a pretty major omission to me. Is support planned?
I'm pretty sure you could write your own transformer to handle this.
Create a class that implements System.Web.Optimization.IBundleTransform.
Then in the Process method get the contents of the embedded resource. This shouldn't be too difficult. This blog post might be helpful.
Then add the transform to the bundle.
e.g.
var bundle = new Bundle("~/Test").Include("~/Content/Site.css");
bundle.Transforms.Add(new EmbeddedResourceTransformer());
Note that I am using the nuget package from System.Web.Optimization, not Microsoft.Web.Optimization (I have no idea why there are two different namespace implementations, and whether the syntax would be the same in both).
I also can't vouch for the performance of doing it this way as opposed to the file system.
Hope that helps!
Just a few comments on above answers since I don't have enough rep. to comment directly...
The answer from Hainesy suggests using a BundleTransform. I believe this is too late in the process to include an embedded resource. The BundleTransform is helpful for converting things inside the css or javascript after the contents are pulled from the original file and before they are put into the bundled file. For example, if you need to modify image URL's in CSS to point to local relative url for dev and to a CDN url for production.
The link from user960567 explains how to use embedded resources, but there's a catch. That process will only work for something like a common control used from another project.
e.g. If you create a textbox that needs CSS and JS then it allows you to create a HTML helper in the common project that will add the textbox and the script tags that pull in the embedded resource into the page. It does not allow you to pull the embedded resource from the common project into a bundle in another project. This will basically create a separate script or style tag for each embedded resource which may not be what you want (at least it's not what I was looking for.)
I've written a detailed article about how you can use the bundle and minification technology to wrap up your external resources here.
I have planned to write my own light weight MVC for PHP, that will be used as base for my sites I develop. I have no problem with PHP, OOP, et al. I have trouble on how to actually load Models In controllers and use them amd loading Controller values into Views. In short, I don't know how M-V-C interact behind the scenes.
Any tutorial (concentrating on that) or any contribution is welcomed!
Thanks!
ASP.NET MVC is open source: http://aspnet.codeplex.com/releases/view/58781
Edit: consider this: I believe you are trying to reinvent the wheel, thinking that those MVC framework out there are heavy and packed with uncessary features (acording to your double use of the word lightweigth). In my experience, I always ended up coding those extra "features" because a framework is required to evolve. Loading models In controllers, using them and loading controller values into views is just the begining. If you want to get started eventually, it would be a better investment to write some helper classes and methods: a popular pattern in the MVC world. Unless you are writing a MVC framework from scratch for fun and I am totally wrong (you said you needed a base to use for your sites ).
Best of luck!
Codeigniter is an open source MVC framework of php.
http://codeigniter.com/user_guide/overview/appflow.html
The major in MVC is first of all your controller class initiated and then calls view.
After google and check how other MVC works I decided to take this route. I redirect all my requests with .htaccess to index.php. Then there I define base paths. After all the definitions I include the core.php which in turn includes all core files to my mvc framework. Then in the same file I create Instances of Registry and router and the game starts from here!
Internals are a bit complex now but that is what I ended with!