I am currently using ASP.NET MVC2 and I have a ActionController that allows me to save only if the form content is valid, something like
public ActionResult Edit(Guid id)
{
//....
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Guid id, DTOUserEdit dto)
{
if ( ModelState.IsValid) Save(user);
return ModelState.IsValid ? RedirectToAction("Index") : (ActionResult)View(dto);
}
This occasion that, if I'm completing incorrectly the editing form it shows again repeatedly.
My question is if I can trust in the following piece of javascript code to determine whether a call is a PostBack, in other words if it helps me to know it's not the first time that I'm visiting that page. I read somewhere that I should not trust in document.referrer because some proxies delete it, then what code should I use?
function isPostBack() {
if (document.referrer != null && document.referrer == window.location.href)
return true;
return false;
}