Friday, September 30, 2011

Action method calling twice in ASP.NET MVC

         This happens due to many reasons.In one my project i have faced this  was an image with an
empty “src”  property and that would call controller once again.

        This is not the issue with  ASP.NET MVC .It is browser behavior .If the response form(Web form )
having any broken div tags  (Unclosed div tags) or Image source is empty then browser thinking that
form not loaded properly and resubmit the form .It causes to call action method twice in ASP.NET MVC

    Precautions to  prevent the issue

  • Maintain all image tags having  “src” or Image URL (if control is ASP.NET ) with valid image url
  • Add alternative description for every image control (ex:  alt=”Home Banner”)
  • Check all div tags closed properly in Web page
  • Validate your each web page once the development is  completed

Once you specify your webpage “url”  in the site and click on check button .it shows the list of issues and description of respective error

Ex: One of the sample web page I have validated using . The result you can find below  snap shot