Search code examples
c#asp.net-mvcasp.net-mvc-3razortightly-coupled-code

MVC3 Tighlty Coupled View Casting Problems


this is my object

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


    }

I have a view that is tightly coupled with Location object.

i have a view that is tightly coupled with ProductContent in my productcontent view i do

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

i get a error saying

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

I am passing Model.ProductLocation which is of type location but why does it still error off?

I am using MVC3 C# Razor


Solution

  • This is a feature of asp.net mvc's RenderPartial. When you pass null as a model, it uses the model of parent view.

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