tags:

views:

43

answers:

1

Having some problems with strongly typed views in ASP.Net MVC...

Master Page:

<div id="footer-container">
    <div id="actual-footer">
        <% Html.RenderAction("GetFooter", "Footer"); %>
    </div>    
</div>

This I think should call the GetFooter action on the FooterController class?

Model (/models/PageFooter.cs):

namespace Web.Models
{
    public class PageFooter
    {


        public PageFooter()
        {
            Title = DateTime.Now.ToString();
        }


        public string Title { get; set; }

    }
}

That's my model which simply on construction populates the Title with datetime.now.

Controller (/Controlers/FooterController.cs):

namespace Web.Controllers
{
    public class FooterController : Controller
    {

        public ActionResult GetFooter()
        {
            return View(new Web.Models.PageFooter());
        }

    }
}

And now the actual view itself...

View (/Views/Footer/Footer.aspx):

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<Web.Models.PageFooter>" %>

<% Html.Label(Model.Title); %>

The problem is it just does not recognise Model.Title which I believe is the conversion.

Any ideas?

+1  A: 

Ok I found the problem.

I had started the project as using MVC Dll's from MVC 1.0.0.0. I had then upgraded the project by installing MVC futures and referencing those DLL's into my web.config. However, I had not updated the web.config file under my Views folder and this still contained references to the 1.0.0.0 versions of the DLL's. Now it works fine.

So, if you include MVC futures and wonder why you cant get strongly typed views check all references in all web.config files.

RemotecUk