2

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?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Brian
  • 37,399
  • 24
  • 94
  • 109

1 Answers1

3

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

Here works fine that way...

Zote
  • 5,343
  • 5
  • 41
  • 43
  • That worked, thanks. As a note, I am not passing all the values for the object in from the form. For others in a similar situation, the only thing I changed from my original code was I made Article the only parameter. I am still loading the Article from the database and calling UpdateModel on it. – Brian Nov 12 '10 at 00:50