This is a migrated thread and some comments may be shown as answers.

validator is not working with @html.Textboxfor

1 Answer 50 Views
Upload
This is a migrated thread and some comments may be shown as answers.
softwebsolutions
Top achievements
Rank 1
softwebsolutions asked on 10 Oct 2012, 01:31 PM

<script type="text/javascript">
 
  
 
  
 
    $(document).ready(function () {
 
  
 
        var validator = $("#tickets").kendoValidator({
 
            rules: {
 
                upload: function (input) {
 
                    if (input[0].type == "file") {
 
                        return input.closest(".k-upload").find(".k-file").length;
 
                    }
 
                    return true;
 
                }
 
            }
 
        }).data("kendoValidator");
 
  
 
  
 
        $("button").click(function (e) {
 
  
 
            if (!validator.validate()) {
 
                e.preventDefault();
 
            }
 
        });
 
    });
 
  
 
   
 
  
 
    $("#fuActivitySheet").kendoUpload({
 
        multiple: false
 
    });
 
  
 
</script>






<div id="tickets">
    @using (Html.BeginForm("UploadNewActivitySheet", "Vendor", FormMethod.Post, new { id = "UploadActivitySheet", enctype = "multipart/form-data", @class = "clearfix padding_t25" }))
{
     
            @Html.TextBoxFor(model => model.UploadedFile, new { id = "fuActivitySheet", name="fuActivitySheet" , type = "file" })
 
               @Html.ValidationMessageFor(m => m.UploadedFile)
        
       <button class="k-button" type="submit">Submit</button>
    
    
}
 
</section>
</div>





[Display(Name = "Activity Sheet: ")]
[Required(ErrorMessage = "Please Select Activity sheet to upload")]
public System.Web.HttpPostedFileBase UploadedFile { get; set; }

Thanks,
J

1 Answer, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Oct 2012, 10:27 AM
Hello,

Please try with below link/Demo.

http://jayeshgoyani.blogspot.in/2012/10/validate-upload-control-in-kendoui.html

Thanks,
Jayesh Goyani
Tags
Upload
Asked by
softwebsolutions
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or