Official "How to" for MVC Editor/Display Templates? - asp.net-mvc

I have been using MVC Editor & Display Templates for a while, but have come to realize that there seems to be very little official documentation on MVC Editor/Display Templates (Html.EditorFor() and Html.DisplayFor()). I found the basic MSDN documentation just showing the technical details (which on their own, are not very helpful), but I'm looking more for an official how-to, sort of like this example.
Are Editor/Display Templates more of an afterthought, and not really widely enough used to justify more in-depth official documentation?
Or, am I blind, and what I'm looking for exists, I just haven't found it yet?

Official documentation? Don't know any off hand, but I know there are a ton of examples. In particular, I like Phil Haack's discussion on model binding to lists. It includes an example for an editor template in a pretty complicated example. There's source code there, too.
Since he's co-authored every MVC Wrox book, I consider him a pretty definitive source:
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
Here's another blog post (non-official) in a similar vein:
http://blogs.msdn.com/b/stuartleeks/archive/2010/03/30/collections-and-asp-net-mvc-templated-helpers-displayfor-editorfor.aspx

best article that I have found for it is:
http://www.growingwiththeweb.com/2012/12/aspnet-mvc-display-and-editor-templates.html
It explains how to create DisplayFor and EditorFor templates really well.

ASP.NET MVC have a lot of materials on http://www.asp.net/mvc with different examples. EditorTemplates and DisplayTemplates is spetial folders for models (like here Quick Tips About ASP.NET MVC – Editor Templates) and you asking about html helpers, not templates.

Related

Where can I find list of Razor control. Example : #Html.TextBox, #Html.DropDownList

I'm learning ASP.NET MVC 4. I'm finding documents to learn about Razor and MVC. I google and read Razor tutorial at w3schools, codeproject but I don't find full document to learn all about Razor controls and its syntax.
Can someone know where I can find it ?
Thank you
I think you're referring to the HtmlHelper class and all it's available extension methods - you can find those in the Extension Methods section on this page.
The ASP.NET website has lots of good documents and walkthroughs to help with learning Razor syntax. This API Quick Reference might be what you're looking for:
http://www.asp.net/web-pages/overview/api-reference/asp-net-web-pages-api-reference#Classes

List of ASP.Net MVC "special" folders/files

Is there a list of the "special" folders and files in ASP.Net MVC? I'm talking about things like "Views/Shared/EditorTemplates" and "Views/_ViewStart.cshtml."
EDIT:
Responding to CodeIgnoto's comment, I'm not asking about general architecture or how to create a site. I want a list of all the "special" folders and files that the ASP.Net MVC uses. There appear to be quite a few poorly documented features of the ASP.Net MVC framework that could be extremely useful. When I stumbled upon the EditorTemplates and DisplayTemplates folders, I was shocked that they weren't really documented anywhere.
I think they should be _Layout.cshtml, App_Codes, App_LocalResosources, App_GlobalResources, Themes, Global.asax, Web.config...
As of June 2013, MSDN has a page on general ASP.NET folders that is relatively complete, but I couldn't find anything more up-to-date than this page for MVC.
My search wasn't exactly extensive, but this document is the most relevant one that is referenced on the official website, so I guess you're right in that something is lacking here.
Unofficial or semi-official information seems to be enough for most people. If you want a definitive reference though, the sources are available.

Upgrading view engine to Razor

I wan't to upgrade my MVC.Net site to 3.0 and also upgrade my asp.net view engine to the Razor.
I have seen that e.g. master pages look a bit different, so are there any tutorials on how to do a switch from asp.net to Razor?
Also how can I update the view engine for an existing site?
I'd also suggest reading the blog posts by ScottGu as they're the best documentation that we've got for Razor.
I can suggest you try this tool for converting the bulk of the views (at least the simple ones):
https://github.com/telerik/razor-converter
But don't get me wrong - the conversion still requires human input and lots of it. Detailed knowledge of the Razor conventions is very much important.
Good luck!
Scott Gu has a good series of blog posts about how Razor layouts work.

Recommendations for learning ASP.NET MVC from a desktop developer's perspective

One of my New Year's Resolutions is to finally learn some web development. I've decided on ASP.NET MVC as I'm a believer in TDD and IoC. I'm looking for a list of topics and perhaps an order to learn them for what I'll need to know to be a solid ASP.NET MVC developer. Perhaps this is embarassing, but the only web experience I have was html pages I made using WYSIWYG editors 5+ years ago when I was in college.
So first, congratulations on picking ASP.NET MVC. I dare say that ASP.NET MVC is easier to work with than WebForms. WebForms tends to take somewhat of a "black-box" approach to the web and treat it more like classic WinForms development. WebForms would probably be a slightly more comfortable technology for you (coming from WinForms development) but MVC will leave you with a greater understanding of how the web works, which is incredibly important.
Before you dive into ASP.NET MVC, you may want to brush up on the basics of HTTP, because it is important to understand when you starting writing action methods that respond differently based on request verbs. It's also nice to know exactly what HTTP headers are, and how they can be leveraged in your application. Anyway, here's my list for you:
Important People and Their Blogs
Phil Haack: He is the lead developer on ASP.NET MVC, and his blog has tons of neat tricks and tips for using it.
Scott Hanselman: He worked with the team on NerdDinner and from time to time his blog has some neat MVC stuff.
Rob Conery: Rob's an avid promoter of ASP.NET MVC and an active open-source contributor. He has tons of code on github for you to browse for inspiration/guidance, and he also has tons of screencasts on his blog and on his business website, TekPub. I recommend purchasing his screencasts from TekPub because he's just an amazing presenter and makes understanding ASP.NET MVC so easy.
Scott Guthrie: He wrote the first chapter with respects to NerdDinner in the Professional ASP.NET MVC 1.0 book, and he always has some cool posts about new features coming in ASP.NET MVC.
Steven Walther: It seems like every time I look at his blog he's got another cool trick or code snippet related to ASP.NET MVC. He's also written a book on ASP.NET MVC that has some pretty good reviews on Amazon.
Reading Material
WDVL: HyperText Transfer Protocol: Again, this is your HTTP tutorial. I've read through part of it and it seems pretty decent. You don't need a rock solid understanding of HTTP, but a general overview of request verbs and headers specifically will help you.
NerdDinner.com Tutorial: This is lengthy step-by-step guide written by ScottGu himself about how to create a basic ASP.NET MVC website from beginning to end.
Profesional ASP.NET MVC 1.0: This is a book by the team that wrote this ASP.NET MVC, and it really does a great job of explaining the framework.
ASP.NET MVC Framework Unleashed: This is Steven Walther's book on the framework. It has some decent reviews on Amazon, though I've never read it myself, so I couldn't really give my opinion one way or the other.
Screencasts
Rob Conery's MVC Storefront Series: These screencasts are amazingly helpful. In the beginning they were working against pre-release copies of the MVC framework, so some stuff has changed, but they're still amazing material for learning ASP.NET MVC.
Scott Guthrie's Presentations on ASP.NET MVC 2: Look at the ASP.NET MVC section of this page. There are some really neat new features coming in ASP.NET MVC 2, and Scott actually builds a good foundation from the ground up with this presentation. He takes you through beginner stuff first and then shows the neat new tricks later.
Phil Haack's MIX09 MVC Session: Great content here straight from the man himself. Phil's actually a great presenter, and there's a lot of good content here.
Phil Haack's MIX09 Advanced MVC Session: Some more advanced stuff and neat tricks from Phil.
Scott Hanselman's File -> New Company MIX09 Session: I actually attended this session while I was at MIX09, and Scott's a great presenter. Well worth a gander :)
Rob Conery and Steven Sanderson TekPub Screencasts: These aren't free, but they're worth every penny. Rob and Steven are amazing teachers, and I can't recommend TekPub screencasts enough. They are top-notch.
IoC and Dependency Injection
Since you mentioned IoC specifically in your OP, there are a few libraries and blog posts that might help you with that:
Simone Chiaretta: How to use Ninject 2 with ASP.NET MVC: I actually use Ninject in my own personal projects, so this is a great resource if you're a fan of Ninject.
Rob Conery's "Hana" Source Code: Sometimes I just love seeing some quality reference code. This is actually the source for Rob's blog. He was using StructureMap originally, but I think he changed recently to Ninject.Mvc.
MVC Storefront DI Screencast: Rob talks about setting up dependency injection in the MVC Storefront. This one uses StructureMap I believe.
TekPub Concepts video (free): Rob goes over the basics of IoC and DI in this video if you need a refresher. It's free too :)
Other Pertinent Web Technologies
Because you're looking to move to the web, there are other languages and technologies that you need to know as well. Below is a list of some brief tutorials to get you started, although each of these subjects could easily warrant a post as big (or bigger) than this one!
HTML: Seems silly that I'm mentioning this here, but I only mention it because there's a lot of push these days to write valid HTML. A majority of accessibility and browser incompatibility issues can be averted by having clean markup. I personally use XHTML in my sites, but any doctype will do :)
JavaScript: This is a neat language that can be used to make many web applications feel more like a desktop application (amongst other things). There are a lot of performance gains and design victories that can be had by properly leveraging JavaScript. Once you feel comfortable with JavaScript, you will probably want to make the move to a JavaScript library to make cross-browser compatibility very easy. My JavaScript library of choice is jQuery.
CSS: This is how you should be applying style to your websites. One of the biggest mistakes a lot of developers make is to make their HTML in charge of presentation (using tables for layouts [holy war], etc. etc.). Arguments and holy wars aside, CSS is a valid skill to have, and it really isn't as hard as some might have you believe :)
I know this seems like a lot, and I've probably inundated you with material to read, however I think it's important to build a solid foundation. Web development is a lot of fun when you are good at it, and it's definitely a great way to make a living! Good luck! ASP.NET MVC is a great framework, and you've made a great choice.
Oh yeah, and there are a few other things you might want to Google in your spare time. They tend to be pretty advanced, so I didn't include them here, but you will run into them when you get more involved in the web world:
AJAX: Makes your web applications perform more naturally and do things in the background.
Web Services: A universal way to exchange data on the web. For example, there are web services that provide weather forecasts and stock quotes. You can consume them and even create some of your own!
XML and JSON: These are used to describe data. When you serialize data on the web, XML and/or JSON are the conventional technologies most developers use. JSON is popular particularly because it can be consumed so nicely within JavaScript.
First step in starting MVC is going through Nerd Dinner Tutorial.
Its the simplest and quickest way to introduce you to the basics of MVC in my opinion.
Thanks
Sorry if this sounds a bit simplistic, but... The tutorials at http://asp.net/mvc, while basic, are good to get you comfortable with the framework. As is NerdDinner. I've found that if you have a development background then learning MVC is not that big of a stretch, so long as you can grasp the MVC pattern which is pretty straight-forward. It'll be more effort to get the web interface side of things up to speed. Your best bet would be to get comfortable with HTML, JavaScript (and AJAX), and CSS so that you can produce a good interface (view).
And the obligatory "learn jQuery" for your web UI.
Get the Nerd Dinner here :
http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf
It is one of the best resources I have used so far
I would start with the following book:
Pro ASP.NET MVC Framework
alt text http://www.apress.com/resource/bookcover/9781430210078?size=medium
It contains great information on starting MVC development from scratch. The sports store example includes much more useful information than Nerd Dinner IMO.
Check out the ASP.NET MVC in Action book and the codecampserver project that goes along with it.
I switched from Webforms to MVC for my day job I while back, and found exposing myself to Rails development, post 6pm at home :), really helpful with the transission as many of Asp.net MVC principles seem to be a direct port from Rails..... and its Rails so you will just love it anyway...;)

Spark T4 templates for ASP.NET MVC

I was just curious if any Spark T4 templates already exist that match/are similar to the out of the box web forms view templates (create, edit, details, etc...). My Google skills didn't lead me to any results.
I've translated the mvc2 templates to spark, feel free to copy:
http://guiftp.free.fr/SparkViewTemplates.rar
T4MVC should work fine with Spark. Here is a related forum thread. That being said, I'm not clear from your initial post that T4MVC is the kind of thing you're looking for.
I meant this part of comment ! if it helps...
# re: T4MVC 2.5.01: added support for Html.RenderAction and Html.Action
#spark_guy: I haven't played extensively with the Spark view engine, but I think that T4MVC should work with it just as well as it works with the aspx view engine. If you hit specific issues, please let me know.
YOu can find all the T4MVC posts at http://blogs.msdn.com/davidebb/archive/tags/T4MVC/, though ideally there would be a single posts that describes it all in one place (I'll try to do this). Note that if you download T4MVC, the readme has good 'getting started' info that tells you what it's all about.

Resources