我在我的MVC应用程序中实现了MVC kendo组合框控件。 kendo组合框控件包含分别绑定到值和文本属性的模型属性。文本属性包含名为CompanyCodeCompany的连接模型属性。我基本上需要提取公司代码,并将其分配给viewmodel中的公司代码属性,因为我需要该值,同时保存到数据库。请注意,我需要国家代码和公司代码。目前,组合框值字段被绑定到CountryCode。目前,使用SalesOrganisation viewmodel填充组合框,并且主窗体使用newrequest viewmodel发布数据。我在新请求viewmodel上尝试了CompanyCodeCompany属性。但是这种做法似乎也可以工作。我明白,combo @(Html.Kendo().ComboBoxFor(model => model.CountryCode)中的这段代码将只绑定国家代码。理想的方法是检索公司从salesorganisation码值和视图模型直接在剃刀将其分配给新的要求。从kendo MVC组合框的DataTextField中检索值并将其分配给视图模型
我不知道的方法采取以获取企业编码值。
<div class="form-group">
@Html.LabelFor(model => model.Company, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-8">
<div class="editor-field">
@(Html.Kendo().ComboBoxFor(model => model.CountryCode)
// .Name("SalesOrganisation")
.HtmlAttributes(new { style = "width:100%" })
.DataTextField("CompanyCodeCompany")
.DataValueField("CountryCode")
.Filter("contains")
.MinLength(3)
.Value(@user.DefaultCountryCode)
.DataSource(dataSource => dataSource
.Read(read => read.Action("RequestHeader_SalesOrganisation", "Request").Type(HttpVerbs.Post))
.ServerFiltering(true)
)
)
</div>
@Html.ValidationMessageFor(model => model.Company, "", new { @class = "text-danger" })
</div>
</div>
销售组织视图模型
public class SalesOrganisationViewModel
{
public string CountryCode { get; set; }
public string CompanyCode { get; set; }
[Display(Name = "Sales Organisation")]
public string Company { get; set; }
public string CompanyCodeCompany
{
get
{
return CompanyCode + " - " + Company;
}
}
}
NewRequest视图模型
public class NewRequestViewModel
{
private string name;
[Display(Name = "Request Id")]
public int RequestID { get; set; }
public int CustomerMasterDataId { get; set; }
[Display(Name = "Customer Number")]
public int CustomerNumber { get; set; }
[Display(Name = "Customer Name")]
public string Name1 { get; set; }
[Display(Name = "Customer Group")]
public string CustomerGroup { get; set; }
public string CountryCode { get; set; }
public string CompanyCodeCompany { get; set; }
}