0

通过序列化我的一个 JavaScript 对象创建的 POST 字符串在发布到我的网页时如下所示:

bikeID=1&vehicleID=23&VIN=1HD1FB416AB666666&slotNum=0&alias=Betsy&BikeCustomizations[0][ CustomizationTypeID] =1&BikeCustomizations[0][ ManufacturerID] =4&BikeCustomizations[0][ CustomizationSubTypeID] =1&BikeCustomizations[1][ CustomizationTypeID] =2&BikeCustomizations[1][ ManufacturerID] =-1

这已发布到我的 ASP.NET MVC 3 应用程序。我得到了基本属性“bikeID,并且我得到了正确数量的项目BikeCustomizations(在这种情况下为 2),但这些对象没有值。

如果我更改 POST 字符串并重新发布(使用 Fiddler)到下面,反序列化工作正常:

bikeID=1&vehicleID=23&VIN=1HD1FB416AB666666&slotNum=0&alias=Betsy&BikeCustomizations[0].CustomizationTypeID=1&BikeCustomizations[0].ManufacturerID=4&BikeCustomizations[0].CustomizationSubTypeID=1&BikeCustomizations[1].CustomizationTypeID=2&BikeCustomizations[1].ManufacturerID=-1

你可以看到区别是BikeCustomizations[1][ CustomizationTypeID] =2vs BikeCustomizations[1].CustomizationTypeID=2

问题:有没有办法强制对象的字符串化不使用时髦的数组样式属性设置器语法?

这是创建对象的 JavaScript:

Cust.buildBike = function (bikeObj) {
if (bikeObj != undefined)
    this.bike = bikeObj;
else
    this.bike = { bikeID: -1 };

this.bike.BikeCustomizations = new Array();
var that = this;

$.each(this.customizationsArr, function (key, obj) {
    if (obj == undefined)
        return true;

    var typeID = obj.ID,
        SubTypeID = obj.SubTypeID,
        ManufacturerID = obj.ManufacturerID,
        Model = obj.Model;

    if (ManufacturerID == -1)
        SubTypeID = undefined;

    that.bike.BikeCustomizations.push({
        CustomizationTypeID: typeID,
        ManufacturerID: ManufacturerID,
        CustomizationSubTypeID: SubTypeID,
        Model: Model
    });
});

return this.bike;
}

...

$('#customizationPageNext').click(function () {
var data = Cust.buildBike(bikeObj);

$.mobile.changePage('/Selection/Calibrations/', { data: data });
});
4

0 回答 0