title: MVC - Passing generic model to a method
body: <p>I have a function <code>FillPdf()</code> which I am using to fill an editable pdf. For now I have defined its parameter type but I have three different forms each having different model so I want is my this <code>FillPdf()</code> receives the respective model and use its data.How to achieve this.</p>
  
  <p><strong>FillPdf.cs</strong></p>
  
  <pre><code>  public static bool FillPdf(M2HDetail m2HUserDetails)
      {
          try
          {
              if (PdfFileSettingViewModel.M2HAuthorizationFormLocation == null)
                  return false;
              var pdfReader = new PdfReader(PdfFileSettingViewModel.M2HAuthorizationFormLocation);
              var sb = new StringBuilder();
              foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
              {
                  sb.Append(de.Key.ToString() + Environment.NewLine);
              }
              var newFile = Path.Combine(PdfFileSettingViewModel.TempFolderLocation, string.Format("{0}_{1}.pdf", "M2HForm",SessionItems.UserId));
              System.IO.File.Copy(PdfFileSettingViewModel.M2HAuthorizationFormLocation, newFile);
  
              var pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
  
              var pdfFormFields = pdfStamper.AcroFields;
              var totalFields = pdfFormFields.Fields.Count;
  
              var myParams = new List&lt;string&gt;();
  
              #region # SetPdfFields #
  
              pdfFormFields.SetField("Text1", m2HUserDetails.LastName);
              pdfFormFields.SetField("Text2", m2HUserDetails.FirstName);
              pdfStamper.FormFlattening = false;
  
              #endregion
  
              pdfStamper.Close();
  
              return true;
  
          }
          catch (Exception ex)
          {
              var files = System.IO.Directory.GetFiles(PdfFileSettingViewModel.TempFolderLocation);
              foreach (var file in files)
              {
                  System.IO.File.Delete(file);
              }
  
              return false;
          }
  
      }
  </code></pre>
  
  <p><strong>Caller function</strong></p>
  
  <pre><code> public ActionResult AuthorizationForm(M2HDetail model)
      {
        var isFillPdfSuccess = PdfFiller.FillPdf(model);
        return View();
       }
  </code></pre>
  
  <p>Now I want that I can use the same pdf method for my other form like this:</p>
  
  <pre><code> public ActionResult AuthorizationFormHippa(HippaAuthForm model)
      {
        var isFillPdfSuccess = PdfFiller.FillPdf(model);
        return View();
       }
  </code></pre>
  
  <p>Also I want that my pdf method could have parameter as model like this:</p>
  
  <pre><code>  public static bool FillPdf(ModelForm model)
  {
   }
  </code></pre>
  
  <p>Please suggest how to achieve this.As I can have more than 3 forms in future and each time I have to write the same method just with different parameter type.</p>