Reputation: 3630
I had this fixed a few months back and it must have just left my mind entirely, and since I just updated my data model on my MVC3 site (update model from db) it is broken again. I am getting the
A potentially dangerous Request.Form value was detected from the client
error. There are plenty of questions out already on this talking about changing some settings in the web.config, but I haven't ever been able to get those to work. The last time I fixed it I am 99% certain I changed something in this generated file:
[DataContract(IsReference = true)]
[KnownType(typeof(Blog))]
[KnownType(typeof(Comment))]
public partial class Post
{
public Post()
{
this.Comments = new HashSet<Comment>();
}
[DataMember]
public int Id { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public System.DateTime DateCreated { get; set; }
//[SOMETHING HERE??]
[DataMember]
public string Content { get; set; }
[DataMember]
public string Tags { get; set; }
[DataMember]
public int BlogId { get; set; }
[DataMember]
public virtual Blog Blog { get; set; }
[DataMember]
public virtual ICollection<Comment> Comments { get; set; }
}
But I cannot for the life of me remember what, and I am not sure what words to search for on the web.
And I know that editing generated code is a big dumb thing to do, but I haven't figured out how to get around that just yet.
Upvotes: 1
Views: 198
Reputation: 1039130
You are looking for the [AllowHtml]
attribute:
[AllowHtml]
[DataMember]
public string Content { get; set; }
And I know that editing generated code is a big dumb thing to do, but I haven't figured out how to get around that just yet.
The problem is that you are passing your WCF domain entities to/from views which is a very bad design approach.
The correct way is to use view models. View models are classes that you specifically design to meet the requirements of your views and then you only pass view models to the views. You will then map between your domain models and view models. AutoMapper is a great tool to simplify this task.
Upvotes: 1