0

EDIT!!!

Just deleted the old stuff cause I consider the conditions to my question have changed a bit.

I'm trying to show a partial view to upload and delete/edit details of current uploaded files.

If I do a generic partial view with the MVC templates for a random model (lots of razer) it shows it perfectly, but when I use the view I've made with the upload form and the draft table for uploaded files It just fades in but not showing anything.

here's the code and markup

Here I have the page where I'm doing the call to the action and showing it as modal

@model GYPTest1.Models.CriteriaViewModel
<div class="panel" id="@Model.Criteria.Code.ToString()">
<div class="well well-lg">
    <h2 style="text-align:center">@Model.CriteriaText</h2>
    <div class="row">
        <div class="col-md-5">
            <label for="Notes" style="text-align:center; ">Notes</label>
            <textarea class="form-control" rows="6" style="resize:none" id="Notes"></textarea>
        </div>
        <div class="col-md-4">
            <label for="Rating" style="text-align:center">Rating</label>
            <div class="btn-group" role="group" aria-label="..." id="Rating" style="margin-bottom:15px">
                <button type="button" class="btn btn-default" data-btn-class="btn btn-zero">0</button>
                <button type="button" class="btn btn-default" data-btn-class="btn btn-one">1</button>
                <button type="button" class="btn btn-default" data-btn-class="btn btn-two">2</button>
                <button type="button" class="btn btn-default" data-btn-class="btn btn-three">3</button>
                <button type="button" class="btn btn-default" data-btn-class="btn btn-four">4</button>
                <button type="button" class="btn btn-default" data-btn-class="btn btn-five">5</button>
            </div>                
            <div class="btn-group" role="group" id="actions">                      
                @Html.ActionLink(" Supports", "Documents", "Diagnostic", new { Id = Model.Criteria.Id, Folder = Model.Path }, new
                   {                            
                        data_target = "#modal-container",                            
                        data_toggle = "modal",
                        @class = "btn btn-info glyphicon glyphicon-edit modal-link",

                   })
            </div>                                                           
        </div>
    </div>
</div>

Partial View I'm trying to show as modal

@model IEnumerable<GYPTest1.Models.DocumentViewModel>    
<form action="/Diagnostic/_Documents" method="post" enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" />

    <input type="submit" name="submit" value="Submit" />
</form>

<table class="table">
    <thead>
        <tr>
            <th>Nombre</th>
            <th>Tamaño</th>
            <th>Download</th>
        </tr>
    </thead>
        <tbody>
    @if (Model.Count() == 0)
        {
                <text>No se encontraron archivos relacionados</text>
        }
        else
        {
            @foreach (var doc in Model)
            {
                <tr>
                    <td>@doc.Name+@doc.Extension</td>
                    <td>@doc.Length</td>
                    <td>Gotta add an action link to download each file</td>
                </tr>
            }
        }
        </tbody>
</table> 

Controller

public ActionResult _Documents(int Id, string Folder)
    {
        List<DocumentViewModel> documentsDetails = new List<DocumentViewModel>();
        List<Document> documents = db.Documents.Where(x => x.CriteriaId == Id).ToList();
        foreach (Document document in documents){
            documentsDetails.Add(new DocumentViewModel
            {
                Name = document.FileName,
                Extension = document.Extension,
                Path = document.FileLocation                    
            });
        }
        ViewBag.CriteriaId = Id;
        ViewBag.Folder = Folder;
        return PartialView("_Documents",documentsDetails);
    }
Moonzenith
  • 25
  • 7
  • You cannot upload files using `Ajax.BeginForm()`. You can use `FormData` with the `$.ajax()` method. Refer [this answer](http://stackoverflow.com/questions/29293637/how-to-append-whole-set-of-model-to-formdata-and-obtain-it-in-mvc/29293681#29293681) for an example –  Dec 07 '16 at 23:05
  • ikr, that's for the posting part, but I can't even load the view to take care of that :( and yep, I had seen that post before – Moonzenith Dec 07 '16 at 23:19

1 Answers1

0

Ok... I gave a closer look to the other partial view that worked (an edit template for a random model) and the only thing I was missing was surrounding all within the upload partial view with Html.BeginForm() ... and that made it

Moonzenith
  • 25
  • 7