My progress with ASP.NET MVC is considered mentionable. My personal project is
Songhay.Web.Mvc.ServerIndex‚ÄĒwhich is the index of my development server. This project helps to get a foothold on current Microsoft technologies within my scope‚ÄĒand it functions in the same manner as a SharePoint ‚ÄúMy Site‚ÄĚ (without SharePoint).
ASP.NET forms and MVC
You really, really can‚Äôt use ASP.NET forms (well) with ASP.NET MVC. The problem starts when you assume that
ViewState will be properly maintained for, say,
GridView paging. Some developers find the
ListView helpful‚ÄĒothers attempt to hack
ViewState with the help of an online tool like KeyCreator.
The problem continues when you get used to using inline code blocks (
<% %>) in views‚ÄĒand you realize (again) that ASP.NET server controls do not support code blocks very well.
|‚ÄúASP.NET MVC doesn‚Äôt work with ViewState and Postback?‚ÄĚ||‚ÄúASP.NET‚Äôs server-side controls work with WebForms, not MVC. MVC doesn‚Äôt use controls in the traditional ASP.NET sense (at least yet).‚ÄĚ|
|‚ÄúIs ViewState relevant in ASP.NET MVC?‚ÄĚ||‚Äú[It‚Äôs] present because
|‚ÄúASP.NET MVC Validation of viewstate MAC failed error‚ÄĚ||I do not recommend seeing the contents of this article as a solution because it opens a security hole in your application.|
MVC Model and View
The presence of the Model is made explicit when it is passed as a Generic Type argument when declaring inheritance for a
<%@ Import Namespace="Songhay.Web.Mvc.ServerIndex.Models" %> <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyViewData>" %>
When a ‚Äúview data‚ÄĚ object is passed to a view, the Model object will now have the properties of this object. This means that you can use
<%=Model.MyViewDataProperty%> instead of something like
"]%>‚ÄĒor that old
Eval syntax Scott Guthrie was showing (with strongly-typed View data) back in 2007. This ‚Äėnew‚Äô (alternative) Model syntax is really cool and is the first time I have seen so explicit an expression of Model and View in an MVC framework! Here is a quote from Microsoft:
You can put views into one of two categories: those that use the
ViewDatadictionary and those that use strong typing. Views that use the
ViewDatadictionary derive from
System.Web.Mvc.ViewPage. Our tag soup example uses this approach. Strongly typed view pages derive from
Tis a generic parameter to specify the type of the model. I recommend you use strong typing.
There is no longer a need to ‚Äúregister‚ÄĚ ASCX files because of the
Html.RenderPartial() helper. Jeffery Palermo insists that you can get rid of ASCX files entirely but I‚Äôm not seeing that being easy in my current version of Visual Studio 2008.
|‚ÄúASP.NET MVC and the templated partial view (death to ASCX)‚ÄĚ||Simply, Jeff‚Äôs
|‚ÄúGuiding Principles For Your ASP.NET MVC Applications‚ÄĚ||This Scott Allen article is very important. It should actually be printed for easy reference.|
|‚ÄúASP.NET MVC Framework (Part 3): Passing ViewData from Controllers to Views‚ÄĚ||
‚ÄúIn addition to supporting a late-bound dictionary approach, the ASP.NET MVC Framework also enables you to pass strongly typed ViewData objects from your Controller to your View. There are a couple of benefits of using this strongly typed approach:‚ÄĚ
‚Äú1. You avoid using strings to lookup objects, and get compile-time checking of both your Controller and View code‚ÄĚ
‚Äú2. You avoid the need to explicitly cast values from the ViewData object dictionary when using strongly-typed languages like C#‚ÄĚ
‚Äú3. You get automatic code intellisense against your ViewData object within both the markup and code-behind of your view page‚ÄĚ
‚Äú4. You can use code refactoring tools to help automate changes across your app and unit-test code base‚ÄĚ
|‚ÄúASP.NET MVC Tip #31‚ÄĒPassing Data to Master Pages and User Controls‚ÄĚ||‚ÄúI‚Äôm not completely convinced by my own tip. I‚Äôm still tempted to use action filters to add view data for my master pages and user controls. The solution described In the last section, using abstract base classes, seems like a lot of work. I‚Äôm curious about how others have solved this problem.‚ÄĚ|
|‚ÄúTyped View Data and Master Pages‚ÄĚ||‚ÄúThe ASP.NET MVC framework supports typed view data through the
MVC Model Definitions and ‚ÄúView Data‚ÄĚ Definitions
A key concept for me is containing the Model in two logical areas: Model Definitions and ‚ÄúView Data‚ÄĚ Definitions. We should all know by now what Model Definitions are (the data-system-centric Model in MVC). What is new to me is the ‚ÄúView Data‚ÄĚ definition‚ÄĒthese define what will be sent as strongly typed data to the View. A previous post records how I divide the data layer conceptually: Procedures, Data Transfer Contracts, Input Definitions and Output Definitions‚ÄĒhere, in ASP.NET MVC land, these ‚ÄúView Data‚ÄĚ Definitions are my Output Definitions. With this single connection in place, I can see how MVC can get to the data‚ÄĒall the rest of the stuff falls into place (as of today). Now that I‚Äô here, let me write these:
- Input Definitions use Data Transfer Contracts to couple with Procedures for data input.
- Output Definitions use Data Transfer Contracts to couple with Procedures for data output.
- Data procedures are loosely coupled from input and output concerns because of Data Transfer Contracts.
I‚Äôve never written (or spoken) these lines before. So it‚Äôs time to get started!
|‚ÄúCollection<T> versus List<T> what should you use on your interfaces?‚ÄĚ||‚Äú‚Ä¶by offering a simpler collection class or interface, you reduce the number of members that users of your API see, and make it easier for them to use.‚ÄĚ This subject is important for ASP.NET MVC because a View will need to iterate over its strongly-typed ‚Äúrows‚ÄĚ of data. The recommended data type for these rows is
|‚ÄúWhat is the difference between ICollection and IDictionary in .NET/C#?‚ÄĚ||‚ÄúFinally, note that these are all interfaces, not classes. .NET gives you a few different types of collections, lists, and dictionaries to choose from, and the interfaces like
By no means do I ‚Äúknow everything‚ÄĚ about ASP.NET MVC. The following table summarizes areas needing more investigation and study:
|‚ÄúASP.NET MVC Preview 5 and Form Posting Scenarios‚ÄĚ||
Posted a little over a year ago, Scott Guthrie writes about the importance of
Then he goes on to Model Binders, ‚ÄúModel Binders provide a way for complex types to be de-serialized from the incoming HTTP input, and passed to a Controller action method as arguments. They also provide support for handling input exceptions, and make it easier to redisplay forms when errors occur (without requiring the end-user to have to re-enter all their data again‚ÄĒmore on this later in this blog post).‚ÄĚ
Other topics of interest are:
|‚ÄúVS 2008 Nested Master Page Support‚ÄĚ||‚ÄúOne of the sites I recommend checking out is http://www.opensourcetemplates.org/. This is an online repository of free HTML site templates that you can browse, download and use.‚ÄĚ|
|‚ÄúASP.NET MVC Tip #1‚ÄĒCreate New HTML Helpers with Extension Methods‚ÄĚ||
‚ÄúYou can add new functionality to the
By looking at source code from big shots, I can see that this technique is encouraged for
|‚ÄúAuthenticating Users with Windows Authentication (C#)‚ÄĚ||‚ÄúAfter you enable Windows authentication, you can use the
|‚ÄúASP.NET MVC Best Practices (Part 1)‚ÄĚ||This Kazi Manzur aricle makes me miss a full-duplex laser printer! This is another one that deserves paper.|