1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
17 public class HttpPostedFileBaseModelBinder : IModelBinder {
\r
19 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
\r
20 if (controllerContext == null) {
\r
21 throw new ArgumentNullException("controllerContext");
\r
23 if (bindingContext == null) {
\r
24 throw new ArgumentNullException("bindingContext");
\r
27 HttpPostedFileBase theFile = controllerContext.HttpContext.Request.Files[bindingContext.ModelName];
\r
29 // case 1: there was no <input type="file" ... /> element in the post
\r
30 if (theFile == null) {
\r
34 // case 2: there was an <input type="file" ... /> element in the post, but it was left blank
\r
35 if (theFile.ContentLength == 0 && String.IsNullOrEmpty(theFile.FileName)) {
\r
39 // case 3: the file was posted
\r