【问题标题】:Problem with Strongly Typed Views强类型视图的问题
【发布时间】:2009-10-12 21:20:35
【问题描述】:

在 ASP.Net MVC 中遇到强类型视图的一些问题...

母版页:

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

认为应该在 FooterController 类上调用 GetFooter 操作?

模型(/models/PageFooter.cs):

namespace Web.Models
{
    public class PageFooter
    {


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


        public string Title { get; set; }

    }
}

这是我的模型,它只是在构造上用 datetime.now 填充标题。

控制器(/Controlers/FooterController.cs):

namespace Web.Controllers
{
    public class FooterController : Controller
    {

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

    }
}

现在是实际视图本身...

视图(/Views/Footer/Footer.aspx):

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

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

问题是它无法识别我认为是转换的 Model.Title。

有什么想法吗?

【问题讨论】:

  • 首先我们检查一下Model的对象类型,看看是不是你想要的。

标签: asp.net-mvc


【解决方案1】:

好的,我找到了问题。

我使用 MVC 1.0.0.0 中的 MVC Dll 启动了该项目。 然后,我通过安装 MVC 期货并将这些 DLL 引用到我的 web.config 中来升级项目。 但是,我没有更新我的 Views 文件夹下的 web.config 文件,它仍然包含对 DLL 的 1.0.0.0 版本的引用。 现在它工作正常。

因此,如果您包含 MVC 期货并想知道为什么无法获得强类型视图,请检查所有 web.config 文件中的所有引用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 2017-05-22
    相关资源
    最近更新 更多