开发者

How do I turn off request validation in MVC3?

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 change FormCollection to Article.

Here works fine that way...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜