Hi guys, I'm trying to get my head around this strongly typed view concept but I keep getting an error hen I view the page. Basically, my application is called modelsTest and I have a CompanyInfo.cs class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace modelsTests.Models
{
public class CompanyInfo
{
public string Name { get; set; }
public string Description { get; set; }
}
}
In the HomeController.cs the About ActionResult method creates a variable and initialize the property of the CompanyInfo class and when I return the View there are two parameters: the name of the view to return and the variable I used to initialize the properties:
public ActionResult About()
{
ViewBag.Message = "Your app description page.";
//ViewBag.CompanyName = "Company X";
//ViewBag.CompanyDescription = "Company X does A, B, C and D.";
var company = new CompanyInfo
{
Name = "Company X",
Description = "Company X does A, B, C and D.",
};
return View("About", company);
}
Now, in the About.cshtml I want to display the values of those properties using a strongly typed view, which, from what I understand, will allow me to reference the variables Name and Description directly. So at the top of the About.cshtml page I need to include, presumably, @model CompanyInfo
but visual studio doesn't like that. Am I missing something really obvious?