locked
MVC3: Compilation error on Webforms Views with @Import directive RRS feed

  • Question

  • User27949333 posted

    If I use the webforms view engine with MVC3, using an import directive on a strongly typed view causes a compile time error.

    e.g, given the fully qualified model class ImportBug.Models.TestModel,

    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TestModel>" %>
    <%@ Import namespace="ImportBug.Models" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    ...
    <h2><%=Model.Name %></h2>
    ... 

    Causes the following:

    Compiler Error Message: CS1061: 'object' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)




    <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TestModel>" %>
    <%@ Import namespace="ImportBug.Models" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">




    Friday, August 6, 2010 12:12 AM

Answers

  • User-1032240251 posted

    Yep, that's a bug we know about. Work around for right now is to make sure the @Page directive is the last pre-processor directive in your file. Will be fixed in Preview 2.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 6, 2010 2:45 AM