Home > Back-end >  The view cannot see/defined my models classes
The view cannot see/defined my models classes

Time:04-28

I want to display all parking spaces details (Id name status) but my view cannot see my models class

The controller:

public async Task<IActionResult> ParkingFinder()
{
        var parking = new ParkingDto();

        using (var client = new HttpClient())
        {
            //Passing service base url
            client.BaseAddress = new Uri(Baseurl);

            //Sending request to find web api REST service resource GetCompanyParkingById using HttpClient
            int id = 5;
            HttpResponseMessage result = await client.GetAsync($"Parking/GetCompanyParkingById/{id}");

            //Checking the response is successful or not which is sent using HttpClient
            if (result.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                parking = result.Content.ReadAsAsync<ParkingDto>().Result;
                
            }
        }

        return View(parking);
}

Then I want to call 'parking' from 'ParkingDto' class in view here:

@using MVC.SmartParkingSystem.Models.ParkingDto;

but I get this error:

The type or namespace name 'ParkingDto' does not exist in the namespace 'MVC.SmartParkingSystem.Models' (are you missing an assembly reference?)

Solution explorer:

enter image description here

CodePudding user response:

I use @model rather than @using, thus the problem solved:

@model SmartParkingSystem.Entity.ParkingDto;
  • Related