I have this class and many properties in it
public class Course
{
public int CourseId { get; set; }
public string CourseName { get; set; }
public Universities? UniversityName { get; set;}
public string Summary { get; set; }
*
*
}
View Model looks like this
public class DetailsViewModels
{
public Course DetailsVMCourse;
public string PageTitle;
*
}
And controller
public IActionResult CourseDetails(int id)
{
DetailsViewModels detailsViewModels = new DetailsViewModels()
{
//loads the course to the view model from a test database
DetailsVMCourse = _courseRepository.FindCourse(id)
};
return View(detailsViewModels);
}
I want to show only if a model property has value in the view. At the moment I am doing this on the view page for each property..
@{ if (Model.DetailsVMCourse.Summary != null)
{
<h4>Cource summary</h4>
<p>
@Model.DetailsVMCourse.Summary
</p>
}
}
Rather than checking every single property with !=null in view, what would be better and efficient way. This is my first project so your help would be greatly appriciated.