I have a problem, I am a beginner with MVC and ASP.NET, so I am trying to do some exercises from a book, but I don't find an error. I create a class, its name is Photo, and I added some Data Annotations, for example [DisplayName(Created Data)]
, and now I have this class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace WebApplication2.Models
{
public class Photo
{
public int PhotoID { get; set; }
[DisplayName("Titolo")]
[Required]
public string Title { get; set; }
public byte[] PhotoFile { get; set; }
public string Description { get; set; }
// [DisplayName("Data creazione")]
// [DisplayFormat(DataFormatString = "{0:dd/mm/yy}", ApplyFormatInEditMode = true)]
public DateTime CreateDate { get; set; }
// [DisplayName("Possessore")]
public string Owner { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
}
my view is:
<div id="photo-title">
@Html.DisplayNameFor(model => model.Title)
@Model.Title
</div>
<div>
@Model.PhotoFile
</div>
<div>
@Model.CreateDate
</div>
I get the error for model.Title
, it is
an expression tree may not contain a dynamic operation.
What does it mean? What do I have to do to solve my problem, seeing the Name for Title to use the Annotations in the View?