What would be best practice to localize your ASP.NET MVC application?
I would like to cover two situations:
one application deployment in IIS which would handle multiple languages
one language/application deployment.
In first situation should you go with some kind of view based thing like, ~/View/EN, ~/View/FI, ~/View/SWE or something different?
What about second case, just application based config via Web.config and point these different languages to different URLs?
You can also take a look here ASP.NET MVC 2 Localization complete guide and ASP.NET MVC 2 Model Validation With Localization these entires will help you if you working with ASP.NET MVC 2.
You would localize your ASP.NET MVC application very much in the same way you would a classic ASP.NET Web Form application.
You wouldn't use different pages/views for each language, but each page would support multiple languages using satellite assemblies.
You can look at Matt Hawley's blog entry for more explanation and examples.
Unfortunately, Matt Hawley's original code doesn't work in the release version of ASP.NET MVC. Check out an updated post: http://blog.eworldui.net/post/2008/10/ASPNET-MVC-Localization-via-View-Engines.aspx
In general, the localization process isn't as smooth in the VS 2008 / ASP.NET MVC world as it is with traditional web forms. http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx
Have a look at Rob Connery's MvcStore project. He does a screencast showing one way to solve the globalization problem.
http://wekeroad.com/2008/04/24/mvcstore-part-5
I've never been convinced of handling localization within a form as Elijah suggests - the different lengths and directions can lead to very complex or vary naff looking forms.
I'm only just starting with MVC but taking the decoupling method you would wan to use the same controller regardless of the language (treating language just as a view) - this would then give you /Controller/Action/language/form
There is good tutorial with recent update on How to localize asp.net mvc application covering all aspects including DisplayName localization, Validation, using Routing (storing culture name in URL), issues with output cache and so on... Alex Adamyan Blog - While my keyboard gently weeps
We actually went a complete different with overriding the
DataAnnotationsMetadaDataProvider.
In there you can make sure that the DisplayNameAttribute values are resolved into the correct language.
Actually you could even get rid of that attribute and resolve by field names only if that would be any help.
I wrote this article a while ago. It uses a custom view engine.
http://blog.oimae.com/2011/02/20/cultured-view-engine-for-mvc/
And another tutorial for different solution
Tutorial: Create ASP.NET MVC localization with language detection
Related
I just need some guidance. I'm fairly new to MVC3 and to web development in general. I want to create my own project that will involve data storage/access (SQL server db) and user log in functionality. I'm not sure were to start, there seem to be so many ways for this and following tutorials doesn't really give the experience of setting up real life project (or its just my impression). Would you guys suggest starting from an empty MVC3 project, or perhaps use the scaffolding feature and build on top of it and use the membership provider built into it ? Some tutorials (by Scott Hanselman) actually explain how to copy and paste the membership feature into a new project. Is this approach suggested ? Any suggestions will help! Thanks!
Here are some tutorials
MVC 3 with razor
ASP.Net website
MVC Music Store
Strongly typed helpers in mvc
Brad Wilson's Blog
MVC Subdomain routing
MVC Partial Views
Some javascript for MVC
MVC Javascript frameworks
JSON and MVC
Form update using JSON in MVC
I'm just starting too, I found this very helpful, especially the videos on the left.
But what I found extremely helpful is the MVC Music Store and the Contoso University site (I recommend to download as PDF; you can see a button to do so at the top).
The NerdDinner tutorial is a great way to start with ASP.NET MVC, although the online version is slightly out of date. However, I can strongly recommend the book that this tutorial (in its updated version) is the first chapter of: Professional ASP.NET MVC 3.
I always used asp.net webforms with the MVP pattern, it works great for what I need, I basically create a project where all my business rules reside, validation etc... and I then implement my views in the webforms project.
Now we're starting to use asp.net MVC and using the MVP patter doesn't make much sense, right? So what could be a good approach to create a scalable and testable project using MVC that won't make me create my data objects and do validation on the controllers. I don' want to have the same code in different places...
If a web user wants to update his/her profile on the site, there would be some validation rules for when a submit button is pushed, like email address cannot be empty, must be valid and must not exist in the database.
These same rules should be applied if I try to update his profile using the internal admin section without having to duplicate the code there...
If you can point me to a good sample project that deals with this would be great!
Thanks in advance!
You should use the MVC pattern with ASP.Net MVC.
The NerdDinner tutorial is a pretty detailed example for MVC, you can also get a book that includes the tutorial (you might want to wait for the version that covers ASP.Net MVC 3). There are plenty of resources on Microsoft's ASP.Net site.
You can always consult Google.
ASP .NET MVC was built with the Model-View-Controller (MVC) pattern in mind. That would be the pattern you'd want to use.
In addition to the resources magnifico provided, I know others have recommended the some other tutorials. I don't know if these have been updated to the latest version of the framework, but they should still serve as decent beginners.
MVC Storefront series
MVC Music Store
Also the Microsoft Patterns & Practices group recently released Project Silk which gets into more advanced techniques involving a lot of AJAX management of the UI. There's interesting stuff there.
We are starting off a new project with sitecore as our CMS. I was thinking of using Sitecore as the Content Authoring Tool and use ASP.net MVC as in the Content delivery(CDA) Side along with Sitecore. Would love to hear your ideas and thoughts on this.
Have anybody tried this?
Is sitecore and MVC competing or Complementing technologies?
Any architectural ideas are welcome.
For certain cases, there can be huge benefit to merging the two. MVC isn't that great of a fit for content-driven sites. However, web applications with structured flow and multiple presentations of data benefit hugely from it. Sitecore has somewhat of a limitation when it comes to multiple presentations of data -- you can only define one set of design details on an item. If you don't have requirements for WYSIWYG editing or easy one-click preview, you can use Sitecore as a data repository, and take advantage of some of the Context values that come from its pipeline (such as language).
A couple modifications are necessary to the Sitecore HTTP pipeline to make this work:
1) If using the aspx extension in IIS6 to get ASP.NET to handle MVC requests (e.g. /Controller.aspx/Action), fix Sitecore's FilePath parsing (there is a bug in how Sitecore resolves the FilePath that will result in the path getting chopped).
To fix this, place a new processor at the start of the httpRequestBegin pipeline.
public class MvcFixHttpProcessor : Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
{
//when using a path such as /Controller.aspx/Blahblahblah, Sitecore's parsing of FilePath can break if Blahblahblah is too long
RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(args.Context));
if (routeData != null)
{
args.Url.FilePath = args.Context.Request.Url.LocalPath;
}
}
}
(Edit 9/13/2011: I haven't had to use the above fix in some time.)
2) Tell Sitecore to ignore URLs that are routed to ASP.NET MVC
To accomplish this, place a new processor in the httpRequestBegin pipeline following the ItemResolver.
public class SystemWebRoutingResolver : Sitecore.Pipelines.HttpRequest.HttpRequestProcessor
{
public override void Process(Sitecore.Pipelines.HttpRequest.HttpRequestArgs args)
{
RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(args.Context));
if (routeData != null)
{
args.AbortPipeline();
}
}
}
If using languages in your Sitecore URLs, you will need to add some custom logic that combines Sitecore link generation with MVC ActionLink generation, to ensure that language is added to the start of your MVC URL. However with the pipeline modifications above, the addition of language to the URL should have no side effects on MVC routing (because Sitecore rewrites the URL after reading the language).
Once again, this approach is only useful for certain types of applications. In those cases though, Sitecore makes an excellent data layer for your model. Look into creating custom Item wrappers to create strongly-typed domain objects based on Sitecore Items.
(Edit 9/13/2011: Custom Item Generator works great for this. http://blog.velir.com/index.php/2010/10/19/custom-item-generator/)
Best of luck.
I think the real question you should be asking here is; if you already have Sitecore in place - why would you want the overhead and complicatino of introducing MVC?
Do you have any business requirements outside the basic web site that would necessitate MVC?
I second Mark's comment about the requirements. Is it worth the risk? You will most likely loose the following features of Sitecore if you decide not to use native rendering functionality:
OMS
Web Forms for Marketers
Conditional Rendering
Page Editor
Page Designer
maybe even more.
I know that Sitecore developers have considered ASP.NET MVC, but I don't know if they've tried it. I can't think of any Sitecore projects that I think would have benefited from ASP.NET MVC. The Sitecore dynamic response engine, pipelines, handlers, wildcards, and other features seem to provide a superset of what you can accomplish with MVC. Similar story with ASP.NET master pages - you could use them with Sitecore, but Sitecore's layout details are superior.
I'm not against ASP.NET MVC with or without Sitecore, but Sitecore seem to provide the features of a controller (really ASP.NET is the controller, and Sitecore just plugs in), your information architecture is the model, and your presentation components are the views.
They sure can be mixed, and I sure do see the value of it :)
No native functionality is lossed with the method I describe in my blog post here:
http://www.chrisvandesteeg.nl/2012/02/26/sitecore-mvc/
As luck would have it, I'm currently working on two large projects using both technologies respectively. And while I'm big fan of both, I can't see any benefits to merging the two.
As far as Sitecore goes, there is a learning curve, but quite honestly in my case, since I actually learned ASP.NET MVC "first" as opposed to Web Forms, the learning curve has also been slightly attributed to some of my inexperience with Web Forms. That said, there still is most definitely a learning curve involved with Sitecore, but there are plenty of training and reference materials floating around to help with that. Also, the web controls that come with Sitecore make it feel a lot less like building a straight Web Forms app. Plus there's the option for using XSLT as a rendering engine which comes in handy as well.
If this is just one project you're thinking about, I would say just stick with Sitecore as it's presentation system is quite well thought out. And as Mark said above, it would really complicate things quite a bit I and I'm also not sure what there is to gain from it even. Also echoing the sentiments of commodore73, building stuff in Sitecore seriously does feel like you're using MVC already, just using a different framework.
MVC in Sitecore has potential, but isn't production ready I think. You're covering unknown ground, as I discovered when creating this blog article.
I know this post is pretty old, but I though I would give my opinion about Sitecore MVC anyway. I've started working on a project a few months back using exclusively Sitecore MVC. There are a lot of restrictions to what I work with since this project must work with or without CMS and be able to fit in with as many CMS as possible (We currently use 2).
ASP.NET MVC was a no brainer for us. It is 2015 and we must go ahead with the new technologies. We are using Sitecore 8, and I think that Sitecore MVC has become mature with Sitecore 7.
There are still a few bumps on the road though. If you plan on using Sitecore with form posts, make sure those are made using AJAX. Doing a validation on a field can be tricky if you use regular POST actions, but there are workarounds.
Now there is Habitat project.
Sitecore Habitat is a Sitecore project that is bulit using the modular architecture. In their website they present a fully working example to install and test.
Habitat project:
https://github.com/Sitecore/Habitat
I'm struggling to find a good reference application for ASP.NET MVC. By "reference", I specifically mean an application that flexes all of the framework's features in the Microsoft-sanctioned manner, such as:
Master pages
Partial views
Strongly-typed models
Authentication
Custom routes
etc...
The open source examples that are out there (CodeCampServer, SutekiShop) either add significantly to the base framework or don't use all of the baked-in features.
Have you seen Rob Connery's MVC Storefront Webcast Series?
http://www.asp.net/learn/mvc-videos/#MVCStorefrontStarterKit
Source Code:
http://www.codeplex.com/mvcsamples/
I asked more or less the same question here: What are some projects which are examples of best practices for ASP.NET MVC?
As for official, the closest would be Rob Connery's which was mentioned.
This isn't official but you could check out Kigg:
http://www.codeplex.com/Kigg
It's a sizable Asp.net MVC Digg-clone with some decent code in it. Used on dotnetshoutout.com
I would consider the Nerd Dinner MVC reference app: http://nerddinner.codeplex.com/ for people just starting
While this might be a little late to the show, I believe that the ASP.net team would like people to start using the MVC Music Store as the official mvc reference example. The Music Store application is using the Razor view engine with Entity Framework's code first approach (also demonstrates database first) along with examples of dependency injection, test driven development, jQuery integration and getting and using NuGet packages.
A second reference example seems to be more on the cutting edge of things and is provided by the Patterns and Practices people. This is called the Silk Project and takes advantage of the latest web standards like HTML5, CSS3 and ECMAScript 5 along with modern web technologies such as jQuery, Internet Explorer 9, and ASP.NET MVC3.
These together would probably show you the newest in ASP.net MVC development along with some pretty neat ideas and examples.
Exactly same as the title of my question,
What is the best way to use MicrosoftReportView control in ASP.NET MVC framework?
I need to use report viewer control in asp.net mvc application, but I am so confused that how to use that control in mvc framework without violation of mvc pattern.
Thanks in advance.
You can mix both WebForms and MVC pages in the same application, so you may want to just develop a single WebForms page for the one that requires the ReportView. Hanselman describes a similar scenario on his blog. If you need it in an MVC page, you may want to look the following for hints on how to do so. I have no idea if this particular control will work or not, since I haven't tried this.
http://codebetter.com/blogs/david.hayden/archive/2007/12/27/asp-net-mvc-and-accessing-server-controls-in-codebehind.aspx
http://flux88.com/blog/leveraging-existing-asp-net-features-in-asp-net-mvc/