Timothy Khouri - SingingEels.com

I subscribe to the "take it apart and rebuild it" approach to learning.

New Article: Model Binders in ASP.NET MVC - Part 2

I normally don't do a "Part 2", but the first article seemed to cause some concerns to many people. The concerns aren't valid, which is why I felt in necessary to address them. The issues stemmed around RESTful URLs, comparing ModelBinders to the ViewState and accessing the database from a ModelBinder. Here's the article: Model Binders in ASP.NET MVC - Part 2

Comments

Richard said:

Your MultiAddressBinder example uses Request["Line1"].Split(',') to extract multiple fields from the posted form. This has three problems:

1. Request[key] checks the query-string, the form, the cookies and the server-variables collections. You only need to check the form (or the query-string for a GET request).

2. If the user enters an address containing a comma, you'll end up with a spurious entry in your array. You should use Request.Form.GetValues("Line1") instead.

3. If the user leaves one of the fields blank on one of the addresses, you have no way of determining which value corresponds to which address. It would probably make more sense to use unique field names for each address.

# October 2, 2008 8:26 PM

Nullable said:

Hey Richard, thanks for the comment. I've never used "Form.GetValues" before, it works perfectly as you stated.

Regarding point #3... I'm not seeing a problem here msyelf if I leave one of the fields blank. I just did 3 addresses, the first was filled with "a"s, the second "b"s and the third "c"s. In the second form, I left out Line2, and everything came across perfectly.

Since the addresses are being built in the order that they are created, each index in the array corresponds to the set of input fields.

As a side point: I was by no means attempting to create the ultimate address rebuilder, but I appreciate the input as I've learned something new!

Thanks again,

-Timothy

# October 2, 2008 10:38 PM

Nullable said:

I've updated the article to use the "Form.GetValues" method now... beautiful!

# October 2, 2008 10:42 PM

JimCPj said:

Suicide. What is it with friends who feel the need to talk about suicide. They come to you on the internet and you talk to them for 2 hours, than they act like nothing happened. You confront them about it and they say they were just having a bad day. What do you do when you've heard this from the same person over and over?  <IMG>fish.cookiestuffing.me/.../IMG>

# October 3, 2008 4:00 AM

kristianej said:

ratified effect oscillation project consensus country

# July 20, 2009 2:55 AM

upwoodande said:

driven article 2050 kyoto institute sun hemisphere

# July 27, 2009 5:40 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)