6 ms·
ASP.NET MVC and WebAPI Tutorials
- lindstorm 14y agoIt's good to see Microsoft investing time and resource to recognize community contributions. They should open similar platforms for Mobile, Azure, SQL and Windows Developers too. www.windowsclient.net used to be a good resource for Windows App programmers, but it's been abandoned
- SwearWord 14y agoOh man do I feel more and more pushed to upgrade our codebase to MVC4...
- phillijw 14y agoWe just did it without too much of a problem. The biggest problems were in the razor syntax
- vyrotek 14y agoI'm curious, is there something specific in MVC4 that you need? Personally, I just want it for WebAPI.
- Encosia 14y agoThe automatic support for routing to .mobile views is really nice, for one thing. The small improvements to Razor (e.g. automatic ~/ parsing and conditional shortcuts) are also nice time/trouble savers.
- vyrotek 14y agoI've been following MVC for a long time and I somehow completely missed the .mobile.cshtml feature! I can actually make use of this now. Thanks :)
- jongalloway2 14y agoThe .mobile.cshtml is included out of the box, but you can also define other specific display modes with a lambda expression: DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone") { ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) }); After calling that, you can create a view (index.iphone.cshtml) and it'll be automatically picked up when the condition's matched. This example uses the user agent, but you can use any logic you'd like - cookie / database call / time of day / whatever.
- vyrotek 14y agoVery nice! What's the best way to develop and debug mobile sites locally? Is there a quick way to force either my browser or VS to go into 'mobile' mode? Edit - Found the answer :) http://www.howtogeek.com/113439/how-to-change-your-browsers-user-agent-without-installing-any-extensions/ http://www.howtogeek.com/113439/how-to-change-your-browsers-...
- tugberk 14y agoTwo of the main reasons are Display Modes and TAP support. Also, you don't need ASP.NET MVC 4 to use ASP.NET Web API. Just install Microsoft.AspNet.WebApi package into your existing ASP.NET MVC 3 project, you will be good to go. Just be careful for the order of routes. Both ASP.NET MVC and Web API routes collected under the same collection and a request may go into another pipeline rather than intended one if routes aren't set up properly.
- vyrotek 14y agoNow Azure just needs to hurry up and release .Net 4.5 on their servers. Until then no MVC4 ,WebAPI, or Entity Framework 5. Scroll down to New Features for a list of changes: http://www.asp.net/whitepapers/mvc4-release-notes http://www.asp.net/whitepapers/mvc4-release-notes
- Encosia 14y agoYou can bin deploy MVC 4 sites to Azure (or regular servers running .NET 4). I have a couple MVC 4 sites running on Azure right now.
- nathantotten 14y agoThis is coming very soon. Scott Guthrie mentioned a few time frames in his recent blog post on Windows Azure Web Sites. http://weblogs.asp.net/scottgu/archive/2012/09/17/announcing-great-improvements-to-windows-azure-web-sites.aspx http://weblogs.asp.net/scottgu/archive/2012/09/17/announcing...
- advancedrei 14y agoYou can deploy .NET 4.5 to Azure right now if you use the Virtual Machines instead of the SDK. We're running a Windows Server 2012 VM with several .NET 4.5 sites on it right now for advancedrei.com and its supplemental sites.
- advancedrei 14y agoYou can also chain the .NET 4.5 installer to run inside a Windows Azure Web Role on deploy, but that is a bigger pain in the ass than a VM. FYI .NET 4.5 will be supported in all roles later this month.
- MatthewPhillips 14y agoI can't figure out why MVC and WebAPI are separate products.
- vyrotek 14y agoThe WebAPI project has an interesting history. It was owned originally by the WCF team and then was taken over by the ASP team. A lot of the supporting code for it comes from a new Namespace too. That makes some things slightly annoying when hosting an API in your MVC application.
- steverb 14y agoThey're not really. WebAPI is built on top of MVC, but uses some different base classes (which is annoying as hell at times). [Edit] Plus what vyrotek said [/Edit] I think it has more to do with getting uptake among the WCF crowd than anything else. IF MS doesn't specifically call it out the folks that had bought into the kool-aid to use WCF for all services probably would never see it. As it is, only 50% of them will see it. The MS stack has a LOT of 80% developers who are buried in the bowels of some organization happily doing the same thing they've been doing since they first learned .NET. Heck, I had a call from an organization the other day looking for a senior developer, but they had to have intimate knowledge of a perticular third parties UI control library, because that was what they were using when they wrote the original application in VB6. Couldn't convince them that they probably don't need the 3rd party controls for an HTML app, not could I convince them that any senior developer worth hiring would be able to understand and use said library in a matter of hours if they were truly needed. Over the last three years I've come to understand that it's I'm not that I'm awesome, it's that most developers are just bad at their jobs (present company probably excluded).
- Encosia 14y agoIt's a common misconception that Web API is built on or tied to MVC. It's not though. You can use it in a WebForms site just as easily as in an MVC site. You can even self-host Web API outside of IIS entirely. Also, Web API isn't intended to replace WCF. The "connected systems" people have a whole different set of needs than people building simple web-facing APIs. I don't think we should expect to see WCF or "Add Service Reference" going away anytime soon.
- nahname 14y agoI've never understood their sick obsession with attributes. When I first started using MVC, I thought it was clever to add HttpPost, HttpDelete, etc... After using a real routing library and then bringing one into my MVC project, it just looks, well... stupid. Gone are my RPC method names. Gone are my untestable Http method -> Action routing. Gone are my magical behavior mixed in due to something in a square bracket.
- vyrotek 14y agoWhat's this real routing library you speak of? I actually just started using an Attribute Routing [1] library for my WebAPI project. I like having my routes defined on the methods that will handle them instead of hidden away in the global. [1] https://github.com/mccalltd/AttributeRouting https://github.com/mccalltd/AttributeRouting
- nahname 14y agoRestfulRouting is nice Edit: That library looks pretty good as well. It does come down to a personal preference thing.
- andywhite37 14y agoI used AttributeRouting for a fairly large ASP.NET MVC 3 project. I found it really clean and useful - I preferred having the routing information declared on the methods themselves, rather than in some generic routing table, or a single catch-all route. With this library, you don't have to explicitly define a route on every method, there are convention-based approaches, and different levels at which you can define the base route, then more specific routes as you get closer to the methods themselves. I also used T4MVC, which may have fallen by the wayside, but that kept a lot of the "magic strings" out of the code. http://mvccontrib.codeplex.com/wikipage?title=T4MVC http://mvccontrib.codeplex.com/wikipage?title=T4MVC
- AndrewNCarr 14y agoThere is nothing magical about attributes in C#, they are a well defined way to declaratively add meta data to your methods, and I've always found them quite useful and effective. Here are a few links that may be insightful on how they work: http://oreilly.com/catalog/progcsharp/chapter/ch18.html http://oreilly.com/catalog/progcsharp/chapter/ch18.html http://msdn.microsoft.com/en-us/library/aa288454%28v=vs.71%29.aspx http://msdn.microsoft.com/en-us/library/aa288454%28v=vs.71%2... http://www.codeproject.com/Articles/2933/Attributes-in-C http://www.codeproject.com/Articles/2933/Attributes-in-C
- cylo 14y agoSlightly off topic but I'm finding it difficult to find this information: How long are ASP.NET MVC releases supported for with bug fixes? MVC4 is out now and presumably next year MVC5 will be out -- does MVC4 continue to receive bug fixes?
- eckyptang 14y agoNot for a minute. The releases are pretty much shelved after v.next. To add to that, the support you do get is crappy, even as a gold partner. ASP.Net MVC is awfully designed and rather buggy as well from experience. I've been using it on a huge project (145 controllers)since CTP2. I wouldn't use it again. we're currently investigating werkzeug, python, sqlalchemy and postgresql as a replacement for a new project, particularly also because we got shafted by SQL 2012 per core licensing. Stay away - you have been warned.
- DennisP 14y agoI've built a fair number of medium-small sites with it and like it pretty well...I'm interested in your perspective with such a large project. Why do you think it's awfully designed? I did just run into a pretty nasty and obscure bug. (That was the first though.)
- jongalloway2 14y agoWhat was the bug? I'd like to make sure it's listed on https://aspnetwebstack.codeplex.com/workitem/list/basic https://aspnetwebstack.codeplex.com/workitem/list/basic if it's not there already.
- DennisP 14y agoThis one: http://stackoverflow.com/questions/8640950/null-reference-exception-when-generating-a-url-with-urlhelper-action-method http://stackoverflow.com/questions/8640950/null-reference-ex... In my case it manifested on ajax calls but not the initial page load. I had a custom grid that worked fine on the first load but blew up when the user tried to page or sort it. And it only happened on production, because the prod server had the component mentioned in the link installed, but the dev and stage servers didn't. Luckily the guy administering the web servers tracked down the configuration difference, googled, and found the above link, and I was able to make a small change to my code to work around it, pre-calculating the url on the initial load and just referencing the resulting string on the ajax call (specifically, using lexical closure instead of calculating the url inside a lambda). That fixed it. This was on MVC3.
- jongalloway2 14y agoI work with the ASP.NET team to coordinate some of the content for this site. We're always interested to hear what you like and don't like about the site, what you'd like to see more of, etc. Thoughts?
- eckyptang 14y agoNot related to the site, but now there is an audience... regarding asp.net mvc: Can we have support and out of band releases for asp.net mvc without having to go through connect or partner support, which are both to be honest, utter shit? Also can you get the API right and leave it right so we don't have to piss around for a week with our container and testing environment. And finally, can you give us something better than razor which has a parser that isn't made of broken twigs and has proper separation of content and programming language (its horrid sorry). Jinja2/django/golang templates FTW. Oh and sort out SQL 2012 licensing. It's going to cost us £768,000 to upgrade out kit from 2008 to 2012. Postgres migration is an order of magnitude cheaper. I'm coming from a large asp.net mvc project and its not pleasant, sorry. Welcome to Microsoft centric development! Content on the web site is pretty good though.
- jongalloway2 14y agoFor your first few question: You can get signed nightly builds of ASP.NET MVC. Instructions are here: https://aspnetwebstack.codeplex.com/ https://aspnetwebstack.codeplex.com/ Depending on the kind of support you're looking for, the discussions and issues on CodePlex may help as well. Otherwise, there's community support (often including ASP.NET team members) in the following places: http://forums.asp.net/1146.aspx/1?MVC http://forums.asp.net/1146.aspx/1?MVC http://stackoverflow.com/ http://stackoverflow.com/ http://jabbr.net/#/rooms/aspnetmvc http://jabbr.net/#/rooms/aspnetmvc There are some other view engines available if you don't like Razor. Since you mentioned Django, I'm guessing you've looked at NDjango(http://ndjango.org/index.php?title=NDjango_Home http://ndjango.org/index.php?title=NDjango_Home). Another one I've been keeping an eye on is Parrot (http://thisisparrot.com/ http://thisisparrot.com/) - still in development, but I really like the syntax. After that it got kinda ranty so not sure if I missed some other questions.
- mikelonnborg 14y agoeckyptany. Can't you by a per core license for sql server 2012? how many cores do you have?
- tga 14y agoMy biggest turnoff about ASP.NET MVC is the lack of documentation, namely a cohesive manual. I find the handful of links to blog posts at http://www.asp.net/mvc/overview http://www.asp.net/mvc/overview ridiculous and absolutely not befitting the only modern web development framework promoted by Microsoft. Take a look at the great Django manual (https://docs.djangoproject.com/en/1.4/ https://docs.djangoproject.com/en/1.4/) to see what I mean.
- kenjackson 14y agoAgreed. It feels like I have to get a book to really really learn MVC. Documentation is one area where it feels like an open source approach is the way to go. Get the community to contribute, along with MS, to a single well-defined structured document.