I hope someone can help me with this.
I am using VS 2012 and MVC4.
I am testing a project using Strongly Typed Model using HttpPostedFileBase. When I try to Scaffold the Views it fails with:
---------------------------
Microsoft Visual Studio
---------------------------
Unable to retrieve metadata for 'ImageTest.Models.ImageHandler'. Value cannot be null.
Parameter name: key
---------------------------
OK
---------------------------
I have tried to Un-Install and then Re-Install MVC as was suggested in a few posts on the net but this has not helped. This is my Model: (Yes I have tried [Key] on the Id but makes no difference)
using System;
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace ImageTest.Models
{
public class ImageHandler
{
public int Id { get; set; }
public string ImageName { get; set; }
public HttpPostedFileBase File { get; set; }
}
}
I thought it may be a Context issue but it does not matter if I create a custom Context or use a predefined one I get the same error. This is the pre-defined Context:
using ImageTest.Models;
using System.Data.Entity;
public class ImageHandlerContext : DbContext
{
public ImageHandlerContext() : base("DefaultConnection")
{
}
public DbSet<ImageHandler> ImageHandler { get; set; }
}
As a Test, if I comment out:
// public HttpPostedFileBase File { get; set; }
I can scaffold the View with no problem. Is this a bug? I can not see in the documentation anywhere that Scaffolding HttpPostedFileBase is not supported. See: HttpPostedFileBase
Thanks in advance.