2017-08-16 103 views
0

我有一個Kendo網格有多列,但我想顯示文檔的名稱,當我點擊它來獲取該文檔的路徑。Kendo網格列顯示ActionLink

查看

columns.Bound(od => od.DocumentListName).Width(150).ClientTemplate("#=generateTemplate(DocumentListName)#"); 

JavaScript函數,顯示文檔

function generateTemplate(DocumentList) { 

     var template = "<ul>" 
     if (DocumentList == null || DocumentList == undefined) { 

      template = template + "<li>N/A</li>"; 
     } else { 
      for (var i = 0; i < DocumentList.length; i++) { 
       template = template + "<li>" + DocumentList[i] + "</li>"; 
      } 
     } 
     return template + "</ul>"; 
    } 

列表,我的ActionResult

public ActionResult GetDocuments(ViewModel VM) 
     { 
      using (var db = new DB()) 
      { 
       var docName = db.Documents.Include("Doc").Where(x => x.Id == VM.Id).Select(z => z.Name).ToList(); 
       if (docName.Count() != 0) { 

       } 
       Vm.DocumentListName = docName; 
       var docPath = db.Documents.Include("Doc").Where(x => x.Id == Vm.Id).Select(z => z.Path).ToList(); 
       VM.DocumentPathList = docPath; 
       return Json(VM, JsonRequestBehavior.AllowGet); 

      } 
     } 

我知道我可以顯示路徑作爲ActionLink的這種方式

columns.Template(@<text>@Html.ActionLink(@item.DocumentPathList.ToString(), "GetDocuments", "Controller") </text>).ClientTemplate("<a href='#=DocumentPathList#</a>").Title("Docs"); 

但是我怎麼能把它們合併?

回答

0
function generateTemplate(DocumentList) { 

     var template = "<ul>"; 
     if (DocumentList == null || DocumentList == undefined) { 

      template = template + "<li> </li>"; 
     } else { 
      for (var i = 0; i < DocumentList.length; i++) { 
       var url = '@Url.Action("DownloadDocument", "Controller")?filename=' + DocumentListName[i]; 
       template = template + "<a href='" + url + "'>" + DocumentList[i] + "</a> "; 
      } 
     } 
     return template + "</ul>"; 
    }