title: How to bring file in physical location to model in MVC
body: <p>I have a model as below</p>
  
  <pre><code>public class request_dtls
  {
      [Key]
      public long request_detail_id { get; set; }
      public string first_name { get; set; }
      public string last_name  { get; set; }
  
      [InverseProperty("request_dtls")]
      public virtual IList&lt;dtls_doc&gt; dtls_doc { get; set; }
  }
  
  public class dtls_doc
  {
      [Key]
      public long doc_line_id { get; set; }
      public long request_detail_id { get; set; }
      public string file_name { get; set; }
      public string document_name { get; set; }
      [NotMapped]
      public HttpPostedFileBase UpFile { get; set; }
  
      [ForeignKey("request_detail_id"), InverseProperty("dtls_doc")]
      public virtual request_dtls request_dtls { get; set; }
  }
  </code></pre>
  
  <p>And in view multiple documents will add to each details and its saving successfully. The file path will save in detail level and dtl_doc table contain document names etc.</p>
  
  <p>Now I need to retrieve the uploaded file and show in another view.</p>
  
  <p>I wrote the view as below</p>
  
  <pre><code>@if (Model != null)
  {
      if (Model.dtls_doc != null)
      {
          for (int i = 0; i &lt; Model.dtls_doc.Count; i++)
      {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.HiddenFor(model &gt; Model.dtls_doc[i].request_detail_id);
              @Html.HiddenFor(model &gt; Model.dtls_doc[i].doc_line_id);
              @Html.TextBoxFor(model =&gt; model.dtls_doc[i].document_name)&lt;/td&gt;
          &lt;td&gt;
              @Html.TextBoxFor(model =&gt; model.dtls_doc[i].UpFile, new { type = "file" })
              &lt;input type="hidden" name="dtls_doc.Index" value="@i" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p>and it give below screen</p>
  
  <p><a href="https://i.stack.imgur.com/nnNJV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nnNJV.png" alt="enter image description here"></a></p>
  
  <p>how can i bring the physically stored files corresponding to each "chooseFile" button like below</p>
  
  <p><a href="https://i.stack.imgur.com/pcQLP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pcQLP.png" alt="enter image description here"></a></p>
  
  <p><strong>Edited</strong></p>
  
  <pre><code> &lt;table id="doc" class="table table-striped table-hover table-bordered"&gt;
  
   &lt;tr&gt;
   &lt;th style="width:200px"&gt;
    Document Name
  &lt;/th&gt;
  
   &lt;th style="width:500px"&gt;
    File to Upload
    &lt;/th&gt;
  &lt;th style="width:6px"&gt;
  &lt;/th&gt;
  &lt;/tr&gt;
  @if (Model != null)
      {
          if (Model.dtls_doc != null)
          {
              for (int i = 0; i &lt; Model.dtls_doc.Count; i++)
          {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.HiddenFor(model &gt; Model.dtls_doc[i].request_detail_id);
                  @Html.HiddenFor(model &gt; Model.dtls_doc[i].doc_line_id);
                  @Html.TextBoxFor(model =&gt; model.dtls_doc[i].document_name)&lt;/td&gt;
              &lt;td&gt;
  @Html.ActionLink("Download File", "download_file", new { id = Model.dtl_doc_dtls[i].doc_line_id })
                  &lt;input type="hidden" name="dtls_doc.Index" value="@i" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  </code></pre>
  
  <p>this give the below result...for existing it will be a link to download and it is downloading.
  For new it will be a File type</p>
  
  <p><a href="https://i.stack.imgur.com/VwO7S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VwO7S.png" alt="enter image description here"></a></p>
  
  <p><strong>template for new added row</strong> </p>
  
  <pre><code>  &lt;table id="Newdoc" style="display:none"&gt;
      &lt;tr&gt;
      &lt;td&gt;&lt;input type="text"  name="dtls_doc[#].document_name" value /&gt;&lt;/td&gt;
  
  &lt;td&gt;
  &lt;input type="file"  name="dtls_doc[#].UpFile" /&gt;
  
  &lt;input type="hidden" name="dtls_doc.Index" value="%" /&gt;
   &lt;/td&gt;
  &lt;td&gt;&lt;input id="doc_delete" class="doc_delete" value="X" type="button"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>Jquery for adding new row</strong></p>
  
  <pre><code> $("#N").click(function (event) {
  
                  event.preventDefault();
                  var index = (new Date()).getTime();
                  var clone = $('#Newdoc').clone();
                  clone.html($(clone).html().replace(/\[#\]/g, '[' + index + ']'));
                  clone.html($(clone).html().replace(/"%"/g, '"' + index + '"'));
                  var html = clone.html();
                  $("#doc").append(clone.html());
  
  
              });
  </code></pre>
  
  <p><strong>Jquery for removing a row</strong></p>
  
  <pre><code> $('#doc').on('click', 'td input.doc_delete', function () {
                  $(this).closest('tr').remove();
              });
  </code></pre>
  
  <p>But when submitting the form the newly added files are not getting at controller..it show 3 count
  <a href="https://i.stack.imgur.com/GFGLb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GFGLb.png" alt="enter image description here"></a></p>