3

I read a lot discussion about how to remove the NO file selected text .

I found that this trick do the job but I need something a little bit different :

<style type="text/css">    
    input[type='file'] {
        color: transparent;
    }
</style>

<input  type="file" />

I need the NO file selected to be removed according to a if condition

Something like if there is a value then remove the No file chosen, else add it.

@if (Model.value != null)
{
    Remove the no file chosen
}
else
{
    Add the no File chosen
}

Is it possible? I use MVC5 Project...

user3241019
  • 811
  • 9
  • 20
Jean Tehhe
  • 1,247
  • 5
  • 19
  • 38
  • possible duplicate of [How can I remove the "No file chosen" tooltip from a file input in Chrome?](http://stackoverflow.com/questions/12035400/how-can-i-remove-the-no-file-chosen-tooltip-from-a-file-input-in-chrome) – Ram May 11 '14 at 13:22
  • @undefined-NO its not since I already read it and Its not based on condition... – Jean Tehhe May 11 '14 at 13:23
  • Adding a condition is not very hard (_if that's the only problem_). – Ram May 11 '14 at 13:24
  • @undefined Yes this is the only problem ,if it is not hard can you help please with example? – Jean Tehhe May 11 '14 at 13:27
  • I try ,I've create MVC project and I've pages for create and update in the create operation I use the file and if user choose file it show the file name,now the problem is on edit if user create data and he go to edit and I use this control (file) I got near to it no file choosen which is not correct since the user already choose one...If I remove the no file chosen (omit like in the post) and use r choose file he dont see the file name,how can I handle it ?:( – Jean Tehhe May 11 '14 at 13:49

1 Answers1

1

You can use CSS class and a bit of js for this:

  @if(Model.value != null){
    <input type="file" onchange="fileOnchange(this)" class="notext"/>
    <script>
      function fileOnchange(el){
        if(el.value){
          el.className = "";
        }
        else{
          el.className = "notext";
        }
      }
    <script/>
    <style type="text/CSS">
    .notext{
      color: transparent;
    }
    <style/>
  }
  else
  {
    <input type="file" />
  }
Dmitry Zaets
  • 3,289
  • 1
  • 20
  • 33