Asp – Why can’t an ASP.NET MVC strongly typed view use an interface

asp.net-mvc

Why can't I use this interface to create a strongly typed view?

public interface IAmAnAsset
{
    int assetID { get; }
    String assetTag { get; set; }
    int? AddedBy { get; set; }
    DateTime addedDate { get; set; }
    int? LocationId { get; set; }
    DateTime? purchasedDate { get; set; }
    int? purchasedby { get; set; }
    DateTime? disposalDate { get; set; }
    int assetModelId { get; set; }
    int? employeeId { get; set; }
    float? depreciated { get; set; }
    IAmAComputer Computer { get;  }
}

When I take that exact item and convert to an abstract class, it lets me create a strongly typed view.

I'm new but I would imagine there's something I'm missing, ASP.NET MVC can work with interfaces, right?

Here's the specific class in the persistence layer I'm trying to make use of to create a strongly typed view.

public class ModelAsset : BufferedLinqEntity2<LqGpsDataContext, asset>, AssetManagementModel.IAmAnAsset
{
...
}

I'm trying to create my first MVC view.

Best Answer

ASP.NET works perfectly fine with interfaces:

public interface IAmAnAsset
{
    int AssetID { get; set; }
}

public class AmAnAsset : IAmAnAsset
{
    public int AssetID { get; set; }
}

public class HomeController : Controller
{
    public ActionResult Index()
    {
        IAmAnAsset model = new AmAnAsset { AssetID = 10  };
        return View(model);
    }
}

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IAmAnAsset>" %>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <p><%= Model.AssetID %></p>
</asp:Content>