How do I turn off request validation in MVC3?

2.6k views Asked by At

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...

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?

1

There are 1 answers

1
Zote On BEST ANSWER

Try to remove [ValidateInput(false)] and change FormCollection to Article.

Here works fine that way...