Car Inventory - Strongly Typed View

This example demonstrates using a Strongly-Typed View to display a collection of Cars. The controller passes the collection of Car objects to this View using the View Model approach. This View is considered a Strongly-Typed View because it has a Model class assigned to it. Views that have a Model assigned to it can retrieve data using the "Model" keyword within the View's template HTML code. This also requires the Controller to pass the model object to the View using the View() method. This View uses three separate Controller methods to handle the processing of this page. The Controller's "DisplayCarInventory" method is used to query the database, create a collection of Cars, and pass the collection of Cars to the View when requesting it via the View() method. Once the View is passed a Model object, it can use it to generate the HTML content for the page before it is delivered to the client. The View uses the Controller's "SearchByMake" method to process the HTML form that is used to perform a search based on the user input for make. The form uses HTTP Post to submit the form data to the Controller's method. The View uses the Controller's "ViewCarDetails" method to process the clicking of a hyperlink to get more detailed information for the Car. The hyperlink is setup to request the Controller's ViewCarDetails, which delivers a View contain the specific car's detailed information. This is accomplished by dynamically generating a hyperlink for each Car that contains a route parameter value that can be used in processing the request. The hyperlink generated for each Car contains the car's VIN number as the hyperlink's route parameter. The hyperlink uses a TagHelper to indicate the Controller, the Controller method to execute, and the route parameter. See the Razor template code below on how to implement this.



Make: Model: Year: Value:
nissan versa 2025 $100,001.00
test test 2025 $0.00
toyota camry 2024 $38,000.00
Cadillac CTV5 2025 $60,000.00
dqd qdq 2025 $0.00
Cadillac asdasd 2023 $0.00
Ford Crown Victoria 2024 $10,000.00
QEJKBF KJBF 1931 $2,447,242.00
Audi Q7 2024 $68,500.00
BMW 535xi 2023 $56,750.00
BMW 740i 2024 $110,000.00
Chevy Camaro 2020 $35,000.00
Chevy Suburban 2022 $18,799.00
Dodge Charger Hellcat 2023 $58,000.00
Ford Mustang 2024 $44,870.00
Ford Explorer 1994 $2,500.00
Ford Explorer 2024 $38,000.00
GM Yukon 2023 $35,000.00
Cadillac Escalade 2024 $85,000.00
Mercedes-Benz C300 2015 $18,000.00
Mercedes-Benz S550 Maybach 2024 $250,000.00
Mercedes-Benz S550 2024 $100,000.00
Mercedes-Benz GLE350 2024 $90,000.00
Mercedes-Benz C300 2024 $52,750.00
Mercedes-Benz GLS450 2024 $135,000.00
Mercedes-Benz GLE350 2020 $60,000.00
Tesla S-Type 2023 $89,999.00