Skip to content

Instantly share code, notes, and snippets.

@carlhoerberg
Created August 15, 2011 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlhoerberg/1146796 to your computer and use it in GitHub Desktop.
Save carlhoerberg/1146796 to your computer and use it in GitHub Desktop.
Optional validation
[HttpPost]
public ActionResult Create(int id, Projekt model)
{
var p = db.Get<Projekt>(id);
if (p.Typ1Validering)
if (string.IsNullOrEmpty(model.Field))
ModelState.AddModelError("Field", "Fältet får inte vara tomt");
if (ModelState.IsValid)
{
UpdateModel(p);
db.SubmitChanges();
RedirectToAction("/Projekt/Details/"+p.Id);
}
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment