【问题标题】:MVC3 Tighlty Coupled View Casting ProblemsMVC3 紧耦合视图转换问题
【发布时间】:2011-07-11 01:02:33
【问题描述】:

这是我的目标

public class ProductContent
    {
        public Product Product { get; set; }
        public Location ProductLocation { get; set; }


    }

我有一个与 Location 对象紧密耦合的视图。

我有一个与 ProductContent 紧密耦合的视图 在我的产品内容视图中,我这样做了

@Html.Partial("../PartialViews/Location", Model.ProductLocation)

我收到一个错误提示

The model item passed into the dictionary is of type 'ProductContent', but this dictionary requires a model item of type 'Location'.

我正在传递类型为 location 的 Model.ProductLocation 但为什么它仍然出错?

我正在使用 MVC3 C# Razor

【问题讨论】:

  • 视图中的@model 指令是什么?
  • @model ProjectName.Models.DAO.Location
  • 我猜Model.ProductLocation 为空
  • @driushkin:错误消息听起来不像是空错误。
  • @Natasha Thapa:请显示视图的模型声明。

标签: c# asp.net-mvc asp.net-mvc-3 razor tightly-coupled-code


【解决方案1】:

这是asp.net mvc 的RenderPartial 的一个特性。当您将 null 作为模型传递时,它使用父视图的模型。

ASP.NET MVC, strongly typed views, partial view parameters glitch

【讨论】:

    猜你喜欢
    • 2017-05-09
    • 2018-11-19
    • 1970-01-01
    • 2015-05-12
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    相关资源
    最近更新 更多