I'm writing a grid-independent interface for displaying data in ASP.NET MVC applications, and I would like your feedback on the API design.
In my last post, I discussed some of the problems with existing grid components for ASP.NET MVC. Actually, there are a couple more design issues which I forgot to mention in that post. I'll discuss them briefly before talking about View design.
Many grids require two requests in order to display the first page of data: One for the page itself, then a ...
Imagine you're starting a new project using ASP.NET MVC. Let's say it's a project which frequently requires displaying a list of records, like Google or Stack Overflow or an enterprise database application. Which grid should you use?
The obvious answer is, "I don't know. I'm just getting started. Does it really matter, right now?" Don't you wish!
There are many grids available for ASP.NET MVC. If you're prepared to dedicate your project to a single grid at the outset of your project, and n...
In this post, I will demonstrate how to make your own model validation attributes in order to share common validations throughout an ASP.NET MVC application, and which support MVC 2's client-side validation feature.
Validating a ZIP Code
As an example, consider a model for an address.
public class EditModel
{
public Guid Id { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { ...
Html helpers for ASP.NET MVC are static extension methods, which frequently reference the ViewContext and HttpContext. Combined, this can make unit testing a bit tricky. Let's write a new Html helper using a test-first methodology. Let's start with a prototype function:
public static MvcHtmlString MyTable(this HtmlHelper helper, MyModel model, IDictionary<string, object> htmlAttributes)
{
return MvcHtmlString.Empty;
}
I've added just enough cod...
For a project I'm currently working on, I have a need to add some JavaScript at the end of a page in an ASP.NET MVC application. Since this is part of what Html.EnableClientValidation does, I thought that I would check out that source code to see if there was any kind of generalized mechanism for this. No such luck, I'm afraid. But I did learn a bit more about how Html.EnableClientValidation works, so I thought I might write that down in case it turned out to be useful someday.
The Html.Enabl...
Here's some code I wrote:
public class MyBaseController : Controller
{
// ...
public new ISession Session { get; private set; }
// ....
}
ISession is an interface type I wrote which exposes everything I store in the session at runtime. I use constructor injection to assign this to a simple type which maps to the "real" Session during application runtime, and a "mock" session for unit testing. Session, in ASP.NET, is a user-specific cache.
This hides Controller.Session (...
One very popular option for implementing user security in ASP.NET is to use Forms Authentication with the SQL Server membership provider. This provider creates several database tables to store user-related information, as well as a number stored procedures.
From time to time, a developer will attempt to add the ASP.NET Membership/Forms Authentication tables to their Entity Framework model (or LINQ to SQL, NHibernate, etc.) model. Before doing this, they will often have created referential con...
In this post, I will demonstrate how to map entity models to views in an ASP.NET MVC application without worrying about implementation details like eager loading, lazy loading, or having to manually optimize SQL for the task at hand. I will argue that expressing the relationship between an entity model in the presentation model in a LINQ projection is far simpler than other methods of doing this mapping.
Imagine that you've been asked to write a new web application to track employees for a cu...
Last week, I updated our main development branch to ASP.NET MVC 2 preview 2 (from preview 1). In this post, I'll list some of the features I've found, and also issues I encountered and how I resolved them.
New Features
Some of the new features of preview 2 have been discussed elsewhere, so I won't rehash them. But I've also noticed that there is a new attribute, [RequireHttps], which does what you would expect, when added to an action, and a new HTML helper, Html.HttpMethodOverride, which make...
If you are developing a web application which requires authentication or security features not included in the regular ASP.NET membership feature, you might decide to implement these features yourself. But it seems as if the first instinct of many ASP.NET MVC developers is to do this by customizing their Controllers, because they've decided that AuthorizeAttribute can't possibly serve their needs. They will decide that the way to do this is to write some sort of parent Controller type which exam...