abalter abalter - 3 months ago 15
C# Question

ASP.NET MVC 5 tutorial error: The type or namespace name could not be found

I'm working through an ASP.NET MVC 5 tutorial on YouTube. I'm really enjoying it. However, I'm stuck on what seems to be a strange error. Strange meaning I think I have everything typed in as in the tutorial, but VS2013 is flagging me, and I can't figure out what might be wrong. Defining the math variable as a Course seems fine. However, then it doesn't like math.

enter image description here

Models/Course.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyfirstProject.Models
{
public class Course
{
int CourseID { get; set; }
string CourseName { get; set; }
int TotalCredits { get; set; }
}
}


Controllers/XyzController.cs

using MyfirstProject.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyfirstProject.Controllers
{
public class XyzController : Controller
{
// GET: Xyz
public ActionResult Abc()
{
Course math = new Course();
.....
.....

Answer

Clean and rebuild the solution as Jenish Rabadiya mentioned in comment.

Update

Make the attributes public in the following class

 public class Course
{
    public int CourseID { get; set; }
    public string CourseName { get; set; }
    public int TotalCredits { get; set; }
}