本文介绍了我如何使用uploadify和mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建此视图以插入数据并上传文件.在除IE之外的所有浏览器中,它都允许一键上传多个文件.

我发现在uploadify的帮助下,它允许我在所有浏览器中上传多个文件.
我遇到的问题是将捕获文件从uploadify传递回我的代码中,以便与我的控制器一起使用.

这是我的jquery代码和查看代码.


I create this view that insert data and upload files. In every browser except for IE it allows for multiple upload with one click.

I found with help uploadify which allows me upload multiple files in all browser.
The problem I am having is passing the capture files from uploadify into my back in code to work with my controller.

Here my jquery code and view code.


      $(document).ready(function () {

           $('#files').uploadify({

                'swf': '@Url.Content("~/Scripts/uploadify/uploadify.swf")',
                
                'uploader': '@Url.Action("Patients","Doctors")',

                'cancelImage': '@Url.Content("~/Scripts/uploadify/cancel.png")',

                'checkScript': '@Url.Content("~/Scripts/uploadify/uploadify-check-exists.php")',

//              'script': $('form').attr('post'),

                'multi': true,

                'auto': true,

                'queueID': 'custom-queue',

                'removeCompleted': false,

                'onDialogClose': function (queue) {

                     $('#status-message').text(queue.filesQueued + ' files have been added to the queue.');

                },

                'onQueueComplete': function (stats) {

                     $('#status-message').text(stats.successful_uploads + ' files uploaded, ' + stats.upload_errors + ' errors.');

                }

           });
           $("form[action$='Patients']").submit(function () {
                $.ajax({
                     url: $(this).attr("action"),
                     type: "post",
                     data: $(this).serialize(),
                     success: function(data) {
                          $('#files').uploadifySettings('scriptData', { ID: data});
                          $('#files').uploadifyUpload();
                     }
                });
                return false;
           });
      });





查看:





View:

@using (Html.BeginForm("Patients", "Doctors", FormMethod.Post))
{
     
   
 @Html.ValidationSummary(true)
    
      <fieldset>
     
<table>
<tbody>
<tr>
<th colspan="9">Client Information</th>
</tr>
<tr>
<td colspan="1">@Html.LabelFor(m => m.ClientID)@Html.TextBoxFor(m => m.ClientID, new { @style = "width:150px;" })</td>
<td colspan="1">@Html.LabelFor(m => m.DOB)@Html.TextBoxFor(m => m.DOB, new { @style = "width:100px;" })</td>
<td>@Html.LabelFor(m => m.Gender)@Html.DropDownListFor(m => m.Gender, new List<SelectListItem> { new SelectListItem { Text = "Female" }, new SelectListItem { Text = "Male" } })</td>
<td>@Html.LabelFor(m => m.Handedness)@Html.EditorFor(m => m.Handedness)</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.RecordingDate)@Html.TextBoxFor(m => m.RecordingDate, new { @style = "width: 100px;", @class = "datepicker" })</td>
<td>@Html.LabelFor(m => m.TimeRecording)@Html.TextBoxFor(m => m.TimeRecording, new { @style = "width: 100px;" })</td>
<td>@Html.LabelFor(m => m.EO)@Html.CheckBoxFor(m => m.EO)<br />@Html.LabelFor(m => m.EC)@Html.CheckBoxFor(m => m.EC)</td>
<td>@Html.LabelFor(m => m.Task)@Html.TextBoxFor(m => m.Task, new { @style = "width: 150px;" })</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.Referred_for)@Html.TextBoxFor(m => m.Referred_for, new { @style = "width:100px;" })</td>
<td colspan="3">@Html.LabelFor(m => m.Evaluation_Number)@Html.TextBoxFor(m => m.Evaluation_Number, new { @style = "width:100px;" })</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.Years_of_Education)>@Html.TextBoxFor(m => m.Years_of_Education)</td>
<td>@Html.LabelFor(m => m.Marital_Status)@Html.DropDownListFor(m => m.Marital_Status, new List<SelectListItem> { new SelectListItem { Text = "Yes" }, new SelectListItem { Text = "No" } })</td>
<td colspan="2">@Html.LabelFor(m => m.Abnormality)@Html.TextBoxFor(m => m.Abnormality, new { @style = "width:250px;" })</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.Vision)@Html.TextBoxFor(m => m.Vision, new { @style = "width: 150px;" })</td>
<td colspan="3">@Html.LabelFor(m => m.Appearance)@Html.TextBoxFor(m => m.Appearance, new { @style = "width: 250px;" })</td>
</tr>
<tr>
<td>@Html.LabelFor(m => m.Sleep_Disorder)@Html.TextBoxFor(m => m.Sleep_Disorder, new { @style = "width:150px;" })</td>
<td>@Html.LabelFor(m => m.Accident)@Html.TextBoxFor(m => m.Accident, new { @style = "width:150px;" })</td>
<td colspan="2">@Html.LabelFor(m => m.Employed)@Html.TextBoxFor(m => m.Employed, new { @style = "width:150px;" })</td>
</tr>
<tr>
<td colspan="2">@Html.LabelFor(m => m.Veteran)@Html.TextBoxFor(m => m.Veteran, new { @style = "width:250px;" })</td>
<td colspan="2">@Html.LabelFor(m => m.Activities)@Html.TextBoxFor(m => m.Activities, new { @style = "width:150px;" })</td>
</tr>

     <tr>
          <th>Upload all Documents</th>

     </tr>
     <tr>
          
          <td><input type="file" name="files" id="files" multiple="multiple" /><br/>
          <input id="id" name="id" type="hidden" value="data" />
      
          <div id="custom-queue"></div>

               @Html.HiddenFor(m => m.FileUrl)
          </td>
          
     </tr>
     
</tbody>
</table>
   <p>
   <input type="submit"  value="Submit" />
   </p>
</fieldset>
}





public ActionResult Patients(PatientsModel patients, HttpPostedFileBase files)
         {

               if (ModelState.IsValid)
               {
                    var um = new UserManager();
                    Session["clientID"] = Request.Form["ClientID"];
                    um.AddPatients(patients, files); // insert data and files in to database and dynamically create folders.
                    return RedirectToAction("Index");
               }

            return View(patients);
          }

推荐答案




这篇关于我如何使用uploadify和mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 21:36