Reputation: 836
After upgrading from Beta3 to Beta4, I'm now getting what looks like a deadlock(site hanges indefinitely) when calling TryUpdateModelAsync
public ActionResult Edit(ContactModel contactModel)
{
var contact = db.Contact.Find(contactModel.ContactId);
if (ModelState.IsValid)
{
TryUpdateModelAsync(contact);
var result = db.SaveChanges(() => { });
if (result.Success)
return RedirectToAction("Details", "Client", new { id = contact.ClientId });
}
return View(contactModel);
}
original code above was ported from MVC 5 so I was just trying to run synchronously. I get the same result after converting the controller method to Async like this
public async System.Threading.Tasks.Task<ActionResult> Edit(ContactModel contactModel)
{
var contact = db.Contact.Find(contactModel.ContactId);
if (ModelState.IsValid)
{
var updateResult = await TryUpdateModelAsync(contact);
var result = db.SaveChanges(() => { });
if (result.Success)
return RedirectToAction("Details", "Client", new { id = contact.ClientId });
}
return View(contactModel);
}
I took a quick look through the sample projects and I couldn't find any usage of this method, anyone have a working example? or know why this is happening?
Upvotes: 1
Views: 936
Reputation: 8862
Here is a sample of usage of try update model async (in MVC test code), Note this is from the dev branch. You might have to switch to whatever branch you are on.
Your first sample is bad because updating the model async without an await will create a task, but continue over it to the next method.
To figure out why you have a deadlock you want to break into the deadlock and see where is the stack at, does it have to do with tryupdatemodel at all?
If you can create a simple repro in a small project please file a bug in https://github.com/aspnet/mvc/issues
Upvotes: 1