

ASP.NET MVC and WebAPI Tutorials - maidenhead
http://www.asp.net/

======
tga
My 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> 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/>) to see what I mean.

~~~
kenjackson
Agreed. 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.

------
jongalloway2
I 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
Not 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
For your first few question: You can get signed nightly builds of ASP.NET MVC.
Instructions are here: <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://stackoverflow.com/>
<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>). Another one I've
been keeping an eye on is Parrot (<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.

~~~
eckyptang
I'm talking supported builds, not signed builds. You know with the pile of
pre-paid support credits that we get with our partnership agreement which are
supposed to result in solutions. Every support call requires a week long
argument with the lowest grade of software support who phone me up and ask if
they can close the call every day without escalating it. I'm aware of the
support options you mention, which basically result in "yes, just limp along
with the dependency injection problems with ActionFilters in MVC3 for 6
months" or fork and fix it yourself. We chose the latter, but it's expensive
so we might as well forfeit the partner agreement, use Open Source software
and pay someone to maintain our forks and contribute patches to the products.

We've looked at NDjango, but it's based on F# and as we well know, unless a
product is a mainstream MS platform then it's liable to go out of the window
on a whim or is shrouded constantly with uncertainty ( _choke_ silverlight,
original workflow foundation, XNA? etc).

Sorry if this is rather critical and slightly ranty, but I'm slightly pissed
off with maintaining this mess.

~~~
jongalloway2
Can you send me some specifics (jon dot galloway at microsoft dot com)? At a
minimum I'd like to make sure we've got a bug filed on the di / filters issue
you mention, but more importantly I want to see what we can do about the
support issues you're hitting.

------
vyrotek
Now 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>

~~~
advancedrei
You 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
You 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.

------
nahname
I'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
What'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>

~~~
andywhite37
I 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>

------
lindstorm
It'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

------
mikelonnborg
eckyptany. Can't you by a per core license for sql server 2012? how many cores
do you have?

------
cylo
Slightly 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
Not 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
I'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
What was the bug? I'd like to make sure it's listed on
<https://aspnetwebstack.codeplex.com/workitem/list/basic> if it's not there
already.

~~~
DennisP
This one: [http://stackoverflow.com/questions/8640950/null-reference-
ex...](http://stackoverflow.com/questions/8640950/null-reference-exception-
when-generating-a-url-with-urlhelper-action-method)

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.

------
MatthewPhillips
I can't figure out why MVC and WebAPI are separate products.

~~~
steverb
They'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).

~~~
darrelmiller
Web API is actually built on a completely different HTTP pipeline than ASP.NET
products. When it moved to the ASP.NET team, there were a number of changes
made to make it feel more natural to ASP.NET devs. Hence the slight variations
when you dig under the covers. The question we need to ask ourselves, is why
would the ASP.NET team agree to continue to support a completely new HTTP
pipeline.

~~~
MatthewPhillips
Implementation details. To the person using the products, they are nearly
identical, with one being for web sites and one being for APIs. I see no
reason why these should be separate. Please explain.

~~~
tugberk
ASP.NET MVC is approx. 3 years old product and to support the features of the
current ASP.NET Web API in an elegant way, lots of breaking changes would
occur in ASP.NET MVC. This is just one of the reasons. You might also see this
one as another impl. detail but it is the brutal truth.

Gleen Block has a 20 minutes long video on this topic if you need more info:
[http://www.tugberkugurlu.com/archive/why-do-i-need-asp-
net-w...](http://www.tugberkugurlu.com/archive/why-do-i-need-asp-net-web-api-
when-i-already-have-asp-net-mvc)

~~~
MatthewPhillips
What features? The difference between MVC and Web API, to those using it, is
that Web API uses restful routing and MVC does not. That is all.

~~~
tugberk
It's pretty impressive to see people who have no idea about the technology
they are talking about. ASP.NET Web API doesn't force REST at all! Go learn
what that FX does in the first place before leaving comments like this.

------
SwearWord
Oh man do I feel more and more pushed to upgrade our codebase to MVC4...

~~~
vyrotek
I'm curious, is there something specific in MVC4 that you need? Personally, I
just want it for WebAPI.

~~~
Encosia
The 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
I'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
The .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
Very 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-...](http://www.howtogeek.com/113439/how-to-change-your-
browsers-user-agent-without-installing-any-extensions/)

