.net - kendo 下拉列表值未正确传递到服务器端代码
问题描述
我已经在我的 Angular 7 应用程序中实现了剑道下拉列表控件。我将下拉列表绑定到正确绑定数据并在屏幕上呈现的对象。
当我将下拉列表更改为另一个值并尝试保存它时,我可以看到模型中的属性包含更改值的 id,但不包含对象本身。另一件令人担忧的事情是,在服务器端 .net 代码上,它没有最新的更改值。
我认为原因可能是在属性获取方法中,过滤是由 this.Entity.PRIMARY_CLASS_ID 发生的。这里的 Entity 是指 public FUND Entity { get; 放; } 在视图模型中。在客户端,下拉列表绑定到 FundDetails.PrimaryClasses,因此 ntity.PRIMARY_CLASS_ID 的值保持不变。所以我需要实现 valuechange 属性来修改这个值。
谁能告诉我是否遗漏了什么。
用户界面
<label for="inputEmail" class="col-md-2 col-form-label header">Primary Class</label>
<div class="col-md-3">
<div *ngIf="!EditMode">{{FundDetails.PrimaryClasses.DESCRIPTION}}</div>
<kendo-dropdownlist *ngIf="EditMode" style="width:350px" [(ngModel)]="FundDetails.PrimaryClasses" [data]="FundDetails.Classes" [filterable]="false" textField="DESCRIPTION" [valuePrimitive]="true"
valueField="ID"></kendo-dropdownlist>
</div>
零件
saveManager() {
this.fundService.createFund(this.FundDetails)
.subscribe(data => {
this.getFundDetails(this.SelectedFundId);
this.EditMode = !this.EditMode;
},
err => {
this.Error = 'An error has occurred. Please contact BSG';
},
() => {
});
}
视图模型
public class NewFundViewModel
{
public NewFundViewModel()
{
Products = new List<Product>();
}
public FUND Entity { get; set; }
public List<FUND> Entities { get; set; }
public List<VEHICLE_TYPE> VehicleTypes { get; set; }
public List<DOMICILE> Domiciles { get; set; }
public List<CLOSURE_STATUS> ClosureStatuses { get; set; }
public List<INVESTMENT_STATUS> InvestmentStatuses { get; set; }
public List<ACCOUNT_MANDATE> AccountMandates { get; set; }
public ICollection<FUND> FlagshipFunds { get; set; }
public FUND_CLASS PrimaryClass;
public List<FUND_CLASS> Classes { get; set; }
public List<Product> Products { get; set; }
public List<int> BloombergRequiredIds { get; set; }
private FUND_CLASS _primaryClass;
private VEHICLE_TYPE _vehicleType;
private DOMICILE _domicile;
private CLOSURE_STATUS _closureStatus;
private INVESTMENT_STATUS _investmentStatus;
private FUND _flagshipFund;
private ACCOUNT_MANDATE _accountMandate;
public string SelectedHfrProduct
{
get
{
return Entity.HFR_ID.HasValue() && Products.Any(x => x.ShortName == Entity.HFR_ID)
? Products.First(x => x.ShortName == Entity.HFR_ID).Name
: null;
}
}
public FUND FlagShipFund
{
get
{
if (this.Entity.FLAGSHIP_FUND_ID == null) return null;
_flagshipFund = this.FlagshipFunds?.FirstOrDefault(x => x.ID == this.Entity.FLAGSHIP_FUND_ID);
return _flagshipFund;
}
set
{
_flagshipFund = value;
}
}
public INVESTMENT_STATUS InvestmentStatus
{
get
{
if (this.Entity.INVESTMENT_STATUS_ID == null) return null;
_investmentStatus = this.InvestmentStatuses?.FirstOrDefault(x => x.ID == this.Entity.INVESTMENT_STATUS_ID);
return _investmentStatus;
}
set
{
_investmentStatus = value;
}
}
public CLOSURE_STATUS ClosureStatus
{
get
{
if (this.Entity.CLOSURE_STATUS_ID == null) return null;
_closureStatus = this.ClosureStatuses?.FirstOrDefault(x => x.ID == this.Entity.CLOSURE_STATUS_ID);
return _closureStatus;
}
set
{
_closureStatus = value;
}
}
public DOMICILE Domicile
{
get
{
if (this.Entity.DOMICILE_ID == null) return null;
_domicile = this.Domiciles?.FirstOrDefault(x => x.ID == this.Entity.DOMICILE_ID);
return _domicile;
}
set
{
_domicile = value;
}
}
public FUND_CLASS PrimaryClasses
{
get
{
if (this.Entity.PRIMARY_CLASS_ID == null) return null;
_primaryClass = this.Classes?.FirstOrDefault(x => x.ID == this.Entity.PRIMARY_CLASS_ID);
return _primaryClass;
}
set
{
_primaryClass = value;
}
}
public VEHICLE_TYPE VehicleType
{
get
{
if (this.Entity.VEHICLE_TYPE_ID == null) return null;
_vehicleType = this.VehicleTypes?.FirstOrDefault(x => x.ID == this.Entity.VEHICLE_TYPE_ID);
return _vehicleType;
}
set
{
_vehicleType = value;
}
}
public ACCOUNT_MANDATE AccountMandate
{
get
{
if (this.Entity.ACCOUNT_MANDATE_ID == null) return null;
_accountMandate = this.AccountMandates?.FirstOrDefault(x => x.ID == this.Entity.ACCOUNT_MANDATE_ID);
return _accountMandate;
}
set
{
_accountMandate = value;
}
}
public string HFRFundName { get; set; }
}
保存方法
[HttpPut]
[SkipTokenAuthorization]
public void CreateFund(NewFundViewModel model)
{
var fundService = GetService<FUND>();
var fund = fundService.GetWithIncludes(model.Entity.ID);
if (fund != null)
{
fund.NAME = model.Entity.NAME;
fund.IS_ANONYMOUS = model.Entity.IS_ANONYMOUS;
fund.PRIMARY_CLASS_ID = model.PrimaryClasses.ID;
fund.VEHICLE_TYPE_ID = model.VehicleType.ID;
fund.FLAGSHIP_FUND_ID = model.FlagShipFund?.ID;
fund.INVESTMENT_STATUS_ID = model.InvestmentStatus.ID;
fund.CLOSURE_STATUS_ID = model.ClosureStatus.ID;
fund.DOMICILE_ID = model.Domicile.ID;
fund.ACCOUNT_MANDATE_ID = model.AccountMandate?.ID;
fundService.Update(fund);
}
else
{
}
}
解决方案
推荐阅读
- sql - 对子查询/表返回的每一行执行选择并组合(联合)结果
- javafx - 使用时间线或动画类的过渡更好吗?
- c# - 已设置通用操作后如何更新它?
- sql - SQLAnywhere - 如何格式化日期
- string - 在 2019 年 8 月 8 日下午 4:45:19 上使用 DateTime.ParseExact
- jquery - 图像幻灯片开始空白
- python-2.7 - 如何修复“无效参数:得到 3 帧,但动画 gif 只能由 tf.image.decode_gif 或 tf.image.decode_image 解码”
- redis - Spring Data Redis:redis.clients.jedis.exceptions.JedisConnectionException:流的意外结束
- linux - 在 linux 中,echo 和 pipe 如何与 docker 一起工作?
- c# - Asp.net Core 2.2,在静态 html 文件之间移动时,中间件并不总是执行