2013-03-25 67 views
1

嗨,我有2個問題正在運行:圖像文件所需的屬性

  1. 我使用的是運行非常適合其他類型,如文本框,複選框等,但對於這一個它不工作

    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> 
+0

有誰知道解決的辦法???? – user207888 2013-03-25 21:18:14

+0

我知道js文件驗證。它不是一個屬性,但它會做的工作 – 2013-03-25 22:02:59

+0

謝謝我做了我的工作與JS – user207888 2013-03-26 15:57:21

回答

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; 
        } 
       } 
+0

我可以檢查文件大小在同一功能...如果是這樣我怎麼能檢查文件大小? – user207888 2013-03-26 17:52:23