1

我正在使用带有 ASP.NET MVC 4 的 FineUploader 控件以及 Knockout.js 和 require.js。我已经让控件正确加载而没有任何错误,但是当我单击上传时,上传文件时出错。我错过了一个额外的步骤吗?

这是我要遵循的示例: FineUploader Example

这是为提琴手捕获的错误:

{"Message":"An error has occurred.","ExceptionMessage":"No MediaTypeFormatter is available to read an object of type 'FineUpload' from content with media type 'multipart/form-data'.","ExceptionType":"System.InvalidOperationException","StackTrace":"   at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<ExecuteBindingAsync>b__0(HttpParameterBinding parameterBinder)\r\n   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n   at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)"}

这是加载控件的 knockout.bindings.js 文件:

淘汰赛.bindinds.js

define('knockout.bindings', ['ko', 'moment', 'fu', 'toastr'], function (ko, moment, fu, toastr) {
    ko.utils.contains = function (string, startsWith) {
        string = string || "";
        if (startsWith.length > string.length) return false;

        return string.toLowerCase().indexOf(startsWith.toLowerCase()) >= 0;
    };

    ko.bindingHandlers.date = {
        update: function (element, valueAccessor) {
            var value = valueAccessor();
            var date = moment(value());
            var strDate = date.format('LL');
            $(element).text(strDate);
        }
    };

    ko.bindingHandlers.contractuploader = {
        init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
            $(element).fineUploader({
                request: { endpoint: '/api/UploadContract/UploadFile' }
            })
        },
        update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
            // This will be called once when the binding is first applied to an element,
            // and again whenever the associated observable changes value.
            // Update the DOM element based on the supplied values here.
        }
    };

});

这是控制器:

上传合同控制器.cs

public class UploadContractController : ApiController
    {
        [AcceptVerbs("GET", "POST")]
        public FineUploaderResult UploadFile(FineUpload upload)
        {
            try
            {
                return new FineUploaderResult(true, new { extraInformation = 12345 });
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }

如果需要任何其他信息,请告诉我!

4

0 回答 0