views:

88

answers:

3

I have an edit page I want to use to allow editing of user details. When I update some user details and post on my dev machine it works as expected, details are saved to the DB and I am re-directed to the details page which displays the updated information.

When I publish the site to the live server and perform the same actions it basically doesn't come away from the edit page. The only time the page will successfully post and re-direct is if none of the details are changed from the original values.

Here is the code for the posting:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formValues)
{
    var repo = new UserRepository();
    var user = repo.GetById(id);
    try
    {
        double value;
        foreach(var stat in user.Stats)
        {
            var rawValue = formValues[stat.Name];
            if (Double.TryParse(rawValue, out value))
            {
                stat.Value = value;
            }
            else
            {
                ModelState.AddModelError(stat.Name+"Err", "Value must be numerical.");
            }
        }
        UpdateModel(user);

        if (ModelState.IsValid)
        {
            repo.Save();
            return RedirectToAction("details", new { id = user.ID });
        }
        else
            throw new InvalidOperationException();
    }
    catch
    {
        foreach (var issue in user.GetRuleViolations())
        {
            ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
        }
        return View(user);
    } 
}

I am on windows server 2003 + IIS 6.0

A: 

What do you run on the dev machine and what do you run on the live machine?

It could be to do with IIS 6's ability to handle routing.

EDIT

Windows 7 runs IIS 7 Windows 2003 runs IIS 6

this is where I think your lies.

The following link may help:

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx

Burt
Could you elaborate on *run*? I run the website on my dev machine inside VS2008 via the "View page in browser" option. My dev machine is Windows 7.
James
@Burt, I have already actually went through that particular tutorial, I have setup the MVC wildcard etc. The website itself once published is actually a virtual directory if that helps.
James
+3  A: 

Are you sure you're not seeing the correct behavior? You're using a generic try-catch approach, which simply returns the view if there's an issue. Supposing your repo.Save() method fails, without a "rule violation"--then you're just going to see your view again, as there isn't any specific code to deal with anything else.

reallyJim
@reallyJim, good point actually, the ModelState.IsValid will only validate the *User* properties and not the *User.Stats* ones. So perhaps there is an issue internally and because there are no ModelErrors to display nothing is showing. How can I verify that this is the case?
James
Re-throw the exception in the catch block to isolate the issue.
Jay
I'd say catch an actual exception and log it--you may find something in its details you hadn't expected to see.
reallyJim
@reallyJim spot on, was actually a permissions issue on the Live DB! thanks.
James
A: 

It looks to me that there is an error while trying to update the data... Maybe some sort of data connection problem or data type error? You didn't mention if the data is actually saved and if the only problem is the redirection... which is it?

I am almost pretty sure the data is not being saved to the db and thus I'll suggest you take a closer look at your db connections to make sure the db connections are valid for the published site. If the db connection seems to be correct, then verify the data you are entering is valid in the database.

You could also change the code a little bit to find out if the problem is with the database by redirecting the user in case the ModelState.IsValid returns false:

return RedirectToAction("errorpage");
Ricardo
James
It looks like it was a problem saving the data to the db after all.
Ricardo