Pregunta

I have a service call that gets a filtered set of historical records from our database.

I am having some trouble getting my filter to make it to my main mvc call.

[AcceptVerbs("POST")]
public History History( HistoryFilters filters){......}

config.Routes.MapHttpRoute(
  name: "DefaultActionRoute",
  routeTemplate: "api/{controller}/{action}/{id}",
  defaults: new {id = RouteParameter.Optional}
);

amplify.request.define('post', 'ajax', {
    url: '/api/{controller}/{action}',
    dataType: 'json',
    type: 'POST',
    cache: cache
});

//History Filter js
{
  DateRange: { Start: ..., End: ...},
  BetStatus: "unresolved",
  TransactionTypes: "bets"
}

Every time I make my call filters is filled with null values. The JS filter structure matches that of my HistoryFilters class in C#. If I JSON.stringify my filters and change my Api call to string then i get that but it would be nice if it could convert it for me.

Can anyone tell me what i'm missing?

Edit

var amp = function(id, data) {
    return $.Deferred(function(dfd) {
        amplify.request({
            resourceId: id,
            data: data,
            success: dfd.resolve,
            error: dfd.reject
        });
    }).promise();
};

History: function (filters) {
        return amp('post', { controller: 'user', action: 'history', '':filters});
    }


public class HistoryFilters
{
    public DateFilter DateRange { get; set; }
    public string BetStatus { get; set; }
    public string TransactionTypes { get; set; }
}

public class DateFilter
{
    public string Start { get; set; }
    public string End { get; set; }
}
¿Fue útil?

Solución

It is my understanding that AmplifyJS has an issue with setting contentType and therefore can not make this type of call. I removed the amplifyJS call for now and am using just jquery.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top