我们正在研究Kendo MVC UI,我们将数据从一个视图发送到另一个视图,所有数据(测试框,下拉列表)都被传递到除附件(pdf,xlsx)之外的下一个视图.
下面是我们编写的控制器中从代码中捕获并保存数据并将相同数据传递到另一个视图并将数据绑定到kendo控件的代码(也是上传控件)
public ActionResult SaveData(System.Web.Mvc.FormCollection form,IEnumerable<HttpPostedFileBase> files) // insert operation { //*************************// if (form != null) { string ddluserexceptioncategory = Convert.ToString(form["txtexceptioncategory"],CultureInfo.InvariantCulture); if (!string.IsNullOrEmpty(ddluserexceptioncategory)) { ddluserexceptioncategory = ddluserexceptioncategory.Trim(); } if (ddluserexceptioncategory == "User Management") { //Bind the data to the class object(_clsObj) if (files != null) { TempData["FileName"] = files; _clsObj.Files = files; } TempData["SecondViewData"] = _clsObj; return RedirectToAction("ExceptionType","Home",new { id = 0,regionId = _clsObj.RegionId,status1 = "New,In Progress",keyword1 = string.Empty }); } } string regions = "",statusValue = ""; if (form != null) { regions = form["hiddenregionselected"] + ""; statusValue = form["hiddenstatusselected"] + ""; } return RedirectToAction("homepage",new { region = regions,status = statusValue }); }
下面是我们将请求绑定到第二个的代码
@if (TempData["FileName"] != null) { IEnumerable<HttpPostedFileBase> firstFile = (IEnumerable<HttpPostedFileBase>)TempData["FileName"]; <div class="k-dropzone"> <div class="k-button k-upload-button"> <input name="files" type="file" data-role="upload" multiple="multiple" autocomplete="off" tabindex="-1" class="valid" style="display: none;"> <input id="files" name="files" type="file" data-role="upload" multiple="multiple" autocomplete="off"> <ul id="files1" class="k-upload-files k-reset"> @foreach (var file in firstFile) { string filename= Path.GetFileName(file.FileName); <li class="k-file" data-uid="7aa03676-4dac-468e-b34a-99ac44d23040"> <span class="k-icon k-success">uploaded</span> <span class="k-filename" title="@filename">@filename</span> <strong class="k-upload-status"> <span class="k-icon k-delete"></span> </strong> </li> } </ul> </div> </div> <script> jQuery(function() {jQuery("#files").kendoUpload( {"select":uploadselect,"localization":{"select":"Browse file","headerStatusUploading":"uploading..","headerStatusUploaded":"uploded.."},"async":{"saveUrl":"/Home/Save","autoUpload":false,"removeUrl": "/Home/Remove"}});}); </script> } else { @(Html.Kendo().Upload().Name("files").Async(a => a.Save("Save","Home").Remove("Remove","Home").AutoUpload(false)).Multiple(true).Messages(m => { m.Select("Browse file"); }).Events(events => events.Select("uploadselect"))) }
任何建议或帮助非常感谢.
解决方法
我的猜测是问题来自于使用TempData将这些数据从标记中提取到控制器,反之亦然.
您可能知道,在下一个请求完成后,您放入TempData的任何内容都将被丢弃(Using Tempdata in ASP.NET MVC – Best practice,http://www.codeproject.com/Articles/476967/What-is-ViewData-ViewBag-and-TempData-MVC-Option).
我建议尝试使用ViewBag来证明这个理论.如果证明你可能会考虑将这些数据作为复杂对象的一部分传递,而不是使用MVC的数据字典.