title: How to determine postback with javascript and asp.net mvc?
body: <p>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</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>This occasion that, if I'm completing incorrectly the editing form it shows again repeatedly.</p>
  
  <p>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?</p>
  
  <pre><code>function isPostBack() {
      if (document.referrer != null &amp;&amp; document.referrer == window.location.href)
          return true;
      return false;
  }
  </code></pre>