1

我在我的项目中使用 ASP.NET MVC Telerik 编辑器,telerik 编辑器不支持 PDF 上传功能,它支持图像上传,有没有办法可以包含 PDF 上传功能或者有人尝试过这样做吗?

我的设置:

@(Html.Telerik().Editor().Name(clientId)
/*.Encode(false) weird. Settings "Encode(false)" doesn't work on category & product details page
Now we have to manually decode values*/
.Value(Model)
.Tools(tools => tools
.Custom(settings => settings.HtmlAttributes(new { @class = "t-html", onclick = "viewRichHtmlEditorSource" + random + "(event)", title="Edit HTML" })))
.FileBrowser(browser => browser.Browse("Browse", "ImageBrowser")
    .Thumbnail("Thumbnail", "ImageBrowser")
    .Upload("Upload", "ImageBrowser")
    .DeleteFile("DeleteFile", "ImageBrowser")
    .DeleteDirectory("DeleteDirectory", "ImageBrowser")
    .CreateDirectory("CreateDirectory", "ImageBrowser")))

如何在其中添加您建议的功能?

4

1 回答 1

1

是的,它确实支持pdf,我将它用于pdf,它工作得很好。您需要注意的是文件的大小,您必须检查并确保它不超过 5MB

这是我正在使用的示例:

<div class="editor-field">
    @Html.TextBoxFor(model => model.NewFileName)
    @(Html.Telerik().Upload()
       .Name("attachment")
       .Multiple(false)
       .ClientEvents(events => events.OnSelect("onSelect"))
    )
</div>

onSelect 脚本:

function onSelect(e) {
    if (e.files[0].size > 5000000) {
        alert('The file size is too large for upload');
        e.preventDefault();
        return false;
    }
    // Array with information about the uploaded files
    var files = e.files;
    var ext = $('#attachment').val().split('.').pop().toLowerCase();
    if ($.inArray(ext, ['pdf']) == -1) {
        alert('This type of file is restricted from being uploaded due to security reasons');
        e.preventDefault();
    } else {
        $("#NewFileName").val(files[0].name);
    }
    return false;
}

控制器操作必须接收签名中的附件,如下所示:

public ActionResult EditFile(HttpPostedFileBase attachment) {
...
}
于 2012-04-19T12:08:12.790 回答