没有MediaTypeFormatter可用于从媒体类型为“multipart / form-data”的内容中读取“FineUpload”类型的对象

时间:2013-08-29 16:06:08

标签: asp.net-mvc-4 fine-uploader

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

这是我想要遵循的例子: FineUploader Example

以下是为fiddler捕获的错误:

{"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文件:

knockout.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.
        }
    };

});

这是控制器:

UploadContractController.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;
            }
        }
    }

如果需要任何其他信息,请与我们联系!

0 个答案:

没有答案