1

嗨,我遇到了 2 个问题:

  1. 我正在使用 requiredif 属性,该属性非常适合其他类型,如文本框、复选框等,但对于这个它不起作用

    [RequiredIf("DoYouAgree", ErrorMessage = "请上传图片徽标。")] [DisplayName("Upload Logo")] string imgfile { get; 放; }

视图中的代码:

 @*Browse File*@
     <div class="clear"></div>
    <div class="editor-label grid_2">
     <br /><br />   @Html.LabelFor(model => model.imgfile):
    </div>
    <div style="margin-top:38px;" class="grid_2">
        <input type="file" name="imgfile" id="imgfile" />
    </div>
     <div class="editor-label1 grid_3" style="margin-top:40px;margin-left:80px;" >
        Max file size 299*299 px or 44KB
    </div>
    <br /><br /><br /><br />
    <div class="grid_3 error long" style="margin-left:10px;">
    @Html.ValidationMessageFor(model => model.imgfile)
    </div>
    <br />

为什么它不适合这个。

  1. 我有其他文件只需要必需的属性但是当我点击我的按钮而不上传图片时它也不起作用

提前致谢!

[Required(ErrorMessage = "Please upload screenshot image.")]
 [DisplayName("Screen Shots")]
 public string ssimgfile { get; set; }

看法:

div style="margin-top:38px; margin-bottom:20px;" class="grid_2">
        <input type="file" name="ssimgfile" id="ssimgfile" />
            <div class="grid_3 error long" style="margin-left:4px;">
             @Html.ValidationMessageFor(model => model.ssimgfile)
            </div>
</div>
4

1 回答 1

0
I have done my work with javascript:


    $(function () {
        $('form').submit(function () {
            if ($("input[type=radio]:checked").val() == "True") {
                //Logo Image
                var selectedFile = $('#imgfile').val();
                if (selectedFile == "") {
                    alert('please select valid image logo for marketplace');
                    return false;
                }
                else {
                    var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
                    if ($.inArray($('#imgfile').val().split('.').pop().toLowerCase(), fileExtension) == -1) {
                        alert("You are permited to select only '\n.jpeg','.jpg', '.png', '.gif', '.bmp' formats are allowed.");
                        return false;
                    }
                }
于 2013-03-26T16:07:18.503 回答