tags:

views:

47

answers:

2

I have an edit form, that when posted, if successful should move on to the next record

Here is a snippet of the code in the controller:

    if (issues.Count == 0)
    {
        Service.Save(item);
        Service.SaveChanges();
        return Edit(NextId, listingName);
    }
    else
    {
        ModelState.AddRuleViolations(issues);
    }

    return Edit(item.id, listingName);

The id for the next record is correctly passed to the action, but the autogenerated form still has the values of the old item, rather than the new one. I have debugged it and the item is getting loaded and passed to the view fine.

+1  A: 

Have you tried to return the Edit View explicitly instead of returning the method call?

Like so:

return View("Edit", NextId);

Perhaps it is still containing the old posted values and tries to repopulate the model accordingly...

Robban
How would I pass the NextId and listName parameters? Cant seem to spot a method signature for that..
qui
One suggestion would be to wrap them up in a specific Model class, much like the DinnerFormViewModel in Scott Guthrie's Nerddinner application. You can find more information here http://nerddinnerbook.s3.amazonaws.com/Part6.htm
Robban
+2  A: 

Try to do a RedirectToAction instead of returning the View directly.

return RedirectToAction("Edit", new { id = NextId, listingName = listingName });

Also, you are sending the same value of listingName in both cases (validation error and success). Is this correct?

Manticore