title: Validation of the form submitted by Ajaxform jQuery plugin in ASP.NET MVC 5
body: <pre><code>public  class File
  {
      [Key]
      public int FileID { get; set; }
      [Display(Name = &quot;atachfile&quot;)]
      [MaxLength(150)]
      public string atachFile{ get; set; }
  }
  </code></pre>
  <p>I wrote the controller codes of the editing section like this...</p>
  <pre><code>    // GET: /Users/FileUpload/Edit/5
      public ActionResult Edit(int? id)
      {
          if (id == null)
          {
              return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
          }
  
          File file = db.Files.Find(id);
  
          if (file == null)
          {
              return HttpNotFound();
          }
         
          return View(file);
      }
  
      // POST: /Users/FileUpload/Edit/5
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Edit([Bind(Include = &quot;FileID,atachFile&quot;)] File file, HttpPostedFileBase LearnAtach , int id)
      {
          if (ModelState.IsValid)
          {
              if (LearnAtach != null)
              {
                  if (file.atachFile != null)
                  {
                      System.IO.File.Delete(Server.MapPath(&quot;/File/LearnAtach/&quot; + file.atachFile));
                  }
  
                  string[] FileExtension = { &quot;.zip&quot; };
                  string FileType = Path.GetExtension(LearnAtach.FileName);
                  double FileSize = (LearnAtach.ContentLength / 1024.0) / 1024;
  
                  if (FileExtension.Contains(FileType.ToLower()))
                  {
                      if (FileSize &gt; 950)
                      {/
                          ViewBag.sizeatach = &quot;error..filexize&gt;950&quot;;
                          
                          return View(file);
                      }
  
                      file.atachFile = Guid.NewGuid() + Path.GetExtension(LearnAtach.FileName);
                      LearnAtach.SaveAs(Server.MapPath(&quot;/File/LearnAtach/&quot; + file.atachFile));
                  }
                  else
                  {
                      ViewBag.typeatach = &quot;filyType != zip&quot;;
                      
                      this.TempData[&quot;UnSuccessMessage&quot;] = &quot;filyType != zip&quot;;
                      return View(file);
                  }
              }
             
              fileRepository.UpdateFile(file);
              fileRepository.save();
           
              return RedirectToAction(&quot;Index&quot;);
          }
        
          return View(file);
      }
  </code></pre>
  <p>View markup:</p>
  <pre><code>@model DataLayer.File
  
  @using (Html.BeginForm(&quot;Edit&quot;, &quot;FileUpload&quot;, FormMethod.Post, new { enctype = &quot;multipart/form-data&quot;, id = &quot;fileform&quot; }))
  {
      @Html.AntiForgeryToken()
  
      &lt;div class=&quot;form-horizontal&quot;&gt;
  
          @Html.ValidationSummary(true)
          @Html.HiddenFor(model =&gt; model.FileID)
        
  
          &lt;div class=&quot;form-group&quot;&gt;
              @Html.LabelFor(model =&gt; model.atachFile, new { @class = &quot;control-label col-md-2&quot; })
              &lt;div class=&quot;col-md-10&quot;&gt;
                  @Html.TextBoxFor(model =&gt; model.atachFile, new { type = &quot;file&quot;, Name = &quot;LearnAtach&quot;  })
                 
                  @Html.ValidationMessageFor(model =&gt; model.atachFile)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;div class=&quot;col-md-offset-2 col-md-10&quot;&gt;
                  &lt;input  type=&quot;submit&quot; value=&quot;submit&quot; class=&quot;btn btn-success&quot; /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  &lt;div class=&quot;progress progress-striped&quot; style=&quot;direction: ltr&quot;&gt;
      &lt;div class=&quot;progress-bar progress-bar-success&quot;&gt;0%&lt;/div&gt;
  &lt;/div&gt;
  &lt;br /&gt;&lt;br /&gt;
  @section scripts
  {
      &lt;script src=&quot;~/Scripts/jquery-1.10.2.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;script src=&quot;~/Scripts/modal.js&quot;&gt;&lt;/script&gt;
  
      &lt;script&gt;
          $(document).ready(function() {
                      var bar = $('.progress-bar');
                      var percent = $('.progress-bar');
                      var status = $('#status');
               
                      $(&quot;#fileform&quot;).ajaxForm({
  
                          beforeSend: function() {
  
                              status.empty();
                              var percentVal = '0%';
                              bar.width(percentVal);
                              percent.html(percentVal);
                          },
                          uploadProgress: function(event, position, total, percentComplete) {
                              var percentVal = percentComplete + '%';
                              bar.width(percentVal);
                              percent.html(percentVal);
                              //show preloder
                          },
                          success: function() {
                              var percentVal = '100%';
                              bar.width(percentVal);
                              percent.html(percentVal);
                              //hide preloder
                              $(&quot;#Success&quot;).modal();
                          },
                          complete: function(xhr) {
                              status.html(xhr.responseText);
                          }
                      });
          });
      &lt;/script&gt;
  }
  </code></pre>
  <p>Now the file is uploaded but the validators are not applied .. How can I show the filesize limit and filetype the file on the client side to the user and apply</p>
  <p>In fact, if the condition of file size and format is also wrong, the uploaded file will be saved in the (/File/LearnAtach)folder, but because the condition is incorrect, its path will not be stored in the database.</p>
  <p>Also, if the condition is true, the condition whether this file already exists or deletes the previous one will not be checked. Thanks</p>