Question: What i'm trying to do is to create a dropdown with all my "Stations" from database and when choosing one to zoom on it on map.
I have just created a controller called AdminMapController with this code: 

```
    public class AdminMapController : Controller
    {
        private readonly ApplicationDbContext _context;

        public AdminMapController(ApplicationDbContext context)
        {
            _context = context;
        }
        public ActionResult GetListOfStations()
        {
            ViewBag.ListOfDropdown = _context.Stations.ToList();
            return View("~/Areas/Identity/Pages/Account/AdminMap.cshtml");
        }
        public JsonResult GetAllLocation()
        {
            var data = _context.Stations.ToList();
            return Json(data);
        }

```

and the View ( only the drop down test ):

```
    </style>
    <br/><br/>
    <div>
        <select class="form-control">
            <option>--Select--</option>
            @foreach (var item in ViewBag.ListOfDropdown)
            {
                <option value ="@item.Id">@item.Name</option>
            }
        </select>
    </div>
    <br/>

```

Funny thing that `GetAllLocation` method works properly, but `GetListOfStations` throws me the error `NullReferenceException: Object reference not set to an instance of an object.` with these being the "problems": `@foreach (var item in ViewBag.ListOfDropdown)` and `ViewData["Title"] = "Admin Map";`

Any idea how can i fix this?

Answer: 
I think you should use this one in return Action:

```
var model = _context.Stations.ToList();
return View("~/Areas/Identity/Pages/Account/AdminMap.cshtml", model);

```

View:

```
@model List<Stations>
<div>
        <select class="form-control">
            <option>--Select--</option>
            @foreach (var item in Model)
            {
                <option value ="@item.Id">@item.Name</option>
            }
        </select>
    </div>

```
Another way if you want to keep no using a model in this case would be to use "ViewData" instead:

```
ViewData["Stations"] = _context.Stations.ToList();

```

And in the view something like this:

```
@foreach (var item in ViewData["Stations"] as IList<Stations>)

```

But I still think a model is more uselful in your case.
Use the ViewData for extra information that wouldn't be part of the model.