In the JQuery Validate plugin, you can validate file extensions like this:
$("#my-form").validate({
rules: {
file: {
required: true,
extension: "xls|csv"
}
});
I have a list of valid extensions in my MVC application that I use server side, and I thought it'd be neat to only maintain it in one place. So I tried to do this:
$("#my-form").validate({
rules: {
file: {
required: true,
extension: @string.Join("|", new FileHelper().ValidFileExtensions))
}
});
But that fails because it's not wrapped in quotes. However, this:
extension: @string.Format("\"{0}\"", string.Join("|", new FileHelper().ValidFileExtensions)))
Results in the MVC engine rendering the quotes as "
markup.
Can I get my file extensions wrapped in quotes?