0

I'm building an interactive website where instructor uploads files for his students as test cases for a their codes. I want to allow students to upload their own test cases if they like.

I'm using radio buttons to select a file and it works perfectly, but I'm not sure how can I allow students to upload a new file to a temp path and pass it to the action method in the last radio button.

This is my code so far:

 <div class="form-horizontal">
        <ul>
            @foreach (var file in Model.files)
            {
                var filename = Path.GetFileName(file);

                <li>
                    @Html.RadioButtonFor(model => model.inputPath, file, new { id = filename })
                    @filename
                </li>

            }
            <li>
                @Html.RadioButtonFor(model => model.inputPath,"Upload", new { id = "Upload" })
                Upload your own
            </li>
        </ul>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Run" class="btn btn-default" id="approve-btn" />
                <input type="submit" value="Cancel" class="btn btn-default" data-dismiss="modal" />
            </div>
        </div>
    </div>

How can I do that?

Lee
  • 11
  • 6

1 Answers1

0

You could use javascript/jQuery to check if the radio button is checked by the function below inside document.ready.

If the radio button is checked do whatever else you need to do inside the if statement.

Document.Ready: Document.Ready Information Here

    $(document).ready(function () {

        // check if upload radio button is checked
        if ($("#Upload").prop("checked", true)) {
            // then do whatever function you want to upload your file

        }

    });

Below is some information on uploading files that may be helpful to read:
jQuery Ajax File Upload
Asynchronous file upload (AJAX file upload) using jsp and javascript
Ajax using file upload
Javascript File Upload

Community
  • 1
  • 1
squinny
  • 79
  • 4
  • 12