Thoughts from Dan Miser RSS 2.0
# Thursday, January 29, 2009

It seems that ASP.NET MVC doesn't allow for strongly-typed partial views. If anyone knows of a clean way to do it, I'd love to know!

Take the following typical page declaration:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Foo>" %>

This declaration allows us to access the Foo.Bar property in the view page using the following syntax: Model.Bar. This works really well, and we even get Intellisense for Foo when accessing the Model property in the editor. In contrast, if we inherited from the non-generic ViewPage, Model becomes a simple object type, which means type-casting to get to our passed in model object.

However, using partial pages with a similar technique does not work. For example, if we have a partial page (ViewPage or ViewUserControl) and call it like below, it will not allow for strong typing of the page:

Html.RenderPartial("DisplayFoo", foo)
If we try to strongly type the page, it will result in an error like this at run-time:
Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage'.

One work-around is to create a code-behind file, and specify the strong typing there, and then inherit the partial page from the code-behind. But I really don't like that. RC1 made great strides to get rid of the code-behind mess, and I would prefer not to reintroduce it just for this.

Update: Thanks to bradleylandis in the ASP.NET MVC forum, he correctly figured out that I had my partial page in a folder other than the Views folder. He mentioned that you need to copy the web.config file from the Views folder to any folder that you serve view pages out of. After doing that, I now have a strongly typed partial page.

Thursday, January 29, 2009 1:22:09 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -
ASP.NET MVC
# Wednesday, January 28, 2009

There were a few changes between ASP.NET MVC Beta and RC1 regarding list binding. For background on list binding, look at Phil Haack's excellent article. Here are the changes that I saw, some good, and some bad:

  • You no longer need to specify the ".index" hidden field. This is good, as it's one less hidden field to take care of.
  • Binding occurs automatically for lists of complex types, but you must have contiguous numbering of the elements, starting with zero. This means that you can no longer specify the index with things like key information. I'm not wild about this change.
  • In the Beta release, binding would only occur for properties of IList. I've been using LightSpeed lately, and that means my property looks like this: EntityCollection<FooType> FooProperty. EntityCollection supports IList, but because it wasn't truly an IList in the class declaration, the default binding didn't work. In the Beta release, I got around this by adding a mirrored property of IList<FooType> and then copying the data over to FooProperty in my controller method.
  • Nested property references, e.g. Foo.Bar, now get the resulting input id renamed to Foo_Bar. This makes it easier to work with jQuery selectors on these elements.

All in all, I'm really liking the RC1 release. I'm looking forward to the release!

Wednesday, January 28, 2009 6:04:53 PM (Central Standard Time, UTC-06:00)  #    Comments [1] -
ASP.NET
# Thursday, October 02, 2008

I'll be out in L.A. for PDC 10/25-10/30. If you're going to be there, too, drop me an email!

Thursday, October 02, 2008 10:22:41 AM (Central Daylight Time, UTC-05:00)  #    Comments [0] -
.NET
# Monday, September 29, 2008

Please RSVP to dmiser@wi.rr.com ASAP if you plan on making this Wednesday's ALT.NET meeting, where we can hopefully cover mocking.

When: 10/1/08 @ 7pm

Where: 10000 Innovation Drive, Suite 260 (SpiderLogic office)
Monday, September 29, 2008 9:58:05 AM (Central Daylight Time, UTC-05:00)  #    Comments [0] -
ALT.NET
# Wednesday, September 03, 2008

Due to lack of responses, I'm canceling the ALT.NET meeting for tonight. Please mark your calendars for Wednesday, 10/1/08 for the next meeting, where we will try to cover mocking.

 

Please send me an email at dmiser@distribucon.com if you plan on making it in October.

Wednesday, September 03, 2008 11:19:19 AM (Central Daylight Time, UTC-05:00)  #    Comments [1] -
ALT.NET
# Wednesday, August 27, 2008

Now that summer is drawing to a close, it's time to think about a meeting of the Milwaukee ALT.NET minds again.

When: Wednesday, September 3rd, 2008 @ 7pm
Where: 10000 Innovation Drive, Suite 260 (SpiderLogic office)

I'm hoping that the topic will be mocking, but I'm open to other suggestions.

If you can RSVP by sending an email to me at dmiser@distribucon.com, I'd appreciate it. That way, we can start to get a handle on head count and have enough food on hand for everyone. Thanks, and hope to see you there.

Wednesday, August 27, 2008 11:27:43 AM (Central Daylight Time, UTC-05:00)  #    Comments [0] -
ALT.NET
# Friday, May 16, 2008
When deploying an ASP.NET web site to IIS 6 on a Windows 2003 server, you may encounter 404 errors when trying to access the aspx pages. The quick solution is to Allow ASP.NET extenstions from the IIS Admin Web Service Extensions node. Neil Kilbride has a much more comprehensive writeup on this here.
Friday, May 16, 2008 9:38:13 AM (Central Daylight Time, UTC-05:00)  #    Comments [1] -
ASP.NET
# Wednesday, May 07, 2008
Sorry for the late notice, but we're going to have to cancel the ALT.NET meeting for this month. We'll get things geared up again for next month.
Wednesday, May 07, 2008 12:32:48 PM (Central Daylight Time, UTC-05:00)  #    Comments [2] -
ALT.NET
# Tuesday, April 15, 2008

If you want to add Membership Provider features to your WebHost4Life application, I've found that you can't use the aspnet_regsql wizard UI. Instead, use the following code at the command prompt:


aspnet_regsql -C "Data Source=sqlNNN.mysite4now.com;Initial Catalog=yourdb;User Id=yourUserName;Password=yourPwd" -A mr

Replace NNN with your assigned address, and obviously replace the other elements of the above connection string, too. :-)

Tuesday, April 15, 2008 4:12:01 PM (Central Daylight Time, UTC-05:00)  #    Comments [0] -
.NET | ASP.NET
Navigation
Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Dan Miser
Sign In
Statistics
Total Posts: 375
This Year: 3
This Month: 0
This Week: 0
Comments: 654
Themes
Pick a theme:
All Content © 2012, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)