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
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.
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
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");
精彩评论