0

I have a problem passing a list from my controller to a view.I have a controller with a method that returns a List of Locations.

    public ActionResult Location()
    {
        List<Location> locations = db.Locations.ToList();
        return View(locations);
    }

And a View that receives this model and will do some stuff like setting this locations in a Map.

@model List<PMG.Models.Entities.Location>

<div id="map" style="height:500px"></div>
<script src="https://maps.googleapis.com/maps/api/js?...=initMap"></script>

But when my controller calls the view i get the error

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[PMG.Models.Entities.Location]', but this dictionary requires a model item of type 'PMG.Models.Entities.User'.

The problem is that my master layout expects a model of type PMG.Models.Entities.User and when i call my controler to load the view it refresh the whole site. How can i do so when i call the method only refresh the body section.

Now im calliung the view by calling the controller method in the way :

 <a href="@Url.Action("Location", "Location")">Locations</a>

Thanks in advance

Jose
  • 37
  • 8
  • 1
    That's the problem with a typed layout. See this question: http://stackoverflow.com/questions/4154407/asp-net-mvc-razor-pass-model-to-layout – Steve Greene Aug 09 '16 at 14:30
  • I was already thinking that maybe type the layout wasnt a good idea, thanks for confirm it. – Jose Aug 09 '16 at 14:37

0 Answers0