I am following along in Professional ASP.NET MVC 2 creating NerdDinner and running into a problem.
I made the change in Code snippet 1-32.txt.
Code:
//
// POST: /Dinners/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
Dinner dinner = dinnerRepository.GetDinner(id);
if (TryUpdateModel(dinner))
{
dinnerRepository.Save();
return RedirectToAction("Details", new { id = dinner.DinnerID });
}
return View(dinner);
}
When I run under the debugger, VS 2010 breaks at
Code:
_Title = StructuralObject.SetValidValue(value,false);
in the following code with the warning "ConstraintException was unhandled by user code"
Code:
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Title
{
get
{
return _Title;
}
set
{
OnTitleChanging(value);
ReportPropertyChanging("Title");
_Title = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("Title");
OnTitleChanged();
}
}
If I continue to debug, the correct view appears as in Figure 1-89.
If I run, but do not debug, I do not get the warning.
What is going on? Shouldn't TryUpdateModel be catching this error? Is the warning appearing because TryUpdateModel is is catching the exception rather than my code? Is this a feature of VS 2010 that I want to switch off? If so, how?
Thank you,
Jeff Cooper