Kendo网格列显示ActionLink

时间:2017-08-16 12:53:41

标签: model-view-controller kendo-ui

我有一个包含多列的Kendo网格,但我想显示文档的名称,当我点击它以获取该文档的路径时。

查看

function ChangePassword() {
  var email = $("#txtForgotPassEmail").val();
  if (email == "") {
    alert("Please enter the Email ID.")
  } else if (!ValidateEmail(email)) {
    alert("please enter valid Email ID.")
  } else {
    $.ajax({
      type: "POST",
      dataType: "json",
      data: {
        "email": email
      },
      url: "/MainIndex/forgotPassword",
      success: function(val) {
        if (val == "0") {
          alert("Please enter the Valid Email ID.")
          $("#txtForgotPassEmail").val("");
        } else {
          $("#ForgotPassDiv").hide();
          $("#ChangePassDiv").show();
        }
      }
    });
  }
/* you add extra }); */
}

显示文档列表的JavaScript函数

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

我的ActionResult

 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>";
    }

我知道我可以用这种方式显示Path作为ActionLink

 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);

            }
        }

但我怎样才能将它们结合起来?

1 个答案:

答案 0 :(得分: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>";
    }