I've installed the RC1 release of MVC 3 and I'm using Entity Framework 4 for my model.
NOTE: I had this working just fine in MVC2, but MVC3 changed how this works.
I've read the following articles and was able to get to the code below...
- Granular Request Validation in ASP.NET MVC 3
- Announcing the ASP.NET MVC 3 Release Candidate
- Validation with the Data Annotation Validators
Here's my EF4 Meta Data model...
[MetadataType(typeof(ArticleMetaData))]
partial class Article
{
}
public class ArticleMetaData
{
[SkipRequestValidation()]
public string Body { get; set; }
}
And here's a simplified version of my controller action...
[HttpPost]
[Authorize(Roles = "Admin")]
[ValidateInput(false)]
public ActionResult Edit(string id, FormCollection values)
{
Article article;
article = GetArticle(id);
UpdateModel(article);
if (ModelState.IsValid)
{
Repository.SaveChanges();
return RedirectToAction("Article", new { id = article.Slug });
}
return View(article);
}
What am I doing wrong? Is there a better pattern for me to be following?
Try to remove
[ValidateInput(false)]
and changeFormCollection
toArticle
.Here works fine that way...