我有一个简单的对象模型 public class License {
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
public string LicenseName { get; set; }
public LicenseType LicenseType { get; set; }
public State State { get; set; }
public DateTime DateIssued { get; set; }
public int ValidFor { get; set; }
}
public class State
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
[StringLength(2)]
[Required]
public string Name { get; set; }
[Display(Name = "Long Name")]
[Required, StringLength(25)]
public string LongName { get; set; }
}
public class LicenseType
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string CreationUserId { get; set; }
[ScaffoldColumn(false), StringLength(20)]
public string LastModifiedUserId { get; set; }
[StringLength(100), Required]
public string Description { get; set; }
}
我正在使用热毛巾模板微风,杜兰达尔,淘汰赛。我有一个简单的添加视图模型
var _licenseAdded = false;
var vm = {
states: ko.observableArray(context.states),
licenseTypes: ko.observableArray(context.licenseTypes),
viewAttached: function () {
var self = this;
$('input[name^="date"]').datepicker();
$('#validFor').spinner({
min: 365,
max: 3650,
step: 30
});
log('add Attached', null, true);
},
activate: function () {
var self = this;
self.original = context.manager.createEntity('License', { licenseName: 'Testing321', dateIssued: moment().format('L') }, null);
log('add Activated', null, true);
},
canDeactivate: function () {
if (_licenseAdded === false) {
return app.showMessage('Are you sure you want to leave this page?', 'Navigate', ['Yes', 'No']);
} else {
return true;
}
},
saveChanges: function () {
$.when(context.saveNewLicense()).done(function () {
_licenseAdded = true;
});
router.navigateTo('home');
},
original: undefined
};
return vm;
这是我的 add.html,一切都很好,并且在保存之前工作得很好。
当我调用 saveChanges 时,发送到控制器的 saveBundle 没有附加导航属性,允许存储正确的 State 和 LicenseType 我只得到: saveBundle { "entities": [ { "Id": -1, "CreationUserId": null , "LastModifiedUserId": null, "LicenseName": "new for testing", "DateIssued": "2013-03-11T04:00:00Z", "ValidFor": 0, "entityAspect": { "entityTypeName": "License :#Volt.Telecom.Licensing.Models", "entityState": "Added", "originalValuesMap": {}, "autoGeneratedKey": { "propertyName": "Id", "autoGeneratedKeyType": "身份”}}}],“saveOptions”:{“allowConcurrentSaves”:假}}
不要以为我能得到比这更多的香草。为什么会发生这种情况?当我在客户端上调试时,状态和 licenseType 导航属性都是正确的并且具有正确的值。