亲切注意: -
我有2个模型类(a)类别(b)产品
public class Category
{
public int CategoryID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public System.DateTime Date1 { get; set; }
public string ListA { get; set; }
public string ListB { get; set; }
public int Count { get; set; }
public decimal Price { get; set; }
public bool decision { get; set; }
public IEnumerable<Product> Products { get; set; }
}
public class Product
{
public string Person { get; set; }
public int ProductID { get; set; }
public bool Chk { get; set; }
public decimal Balance { get; set; }
public decimal Deposit { get; set; }
public decimal Adjustment { get; set; }
public decimal NewBalance { get; set; }
[UIHint("AccountList"), Required]
public string Account { get; set; }
[UIHint("VaryDDL")]
public string VaryDDList { get; set; }
}
网格中的2个下拉列表,第1个ddl-正在使用columns的帐户.ForeignKeys 以及带有editortemplate“AccountList.cshtml”
我正在使用columns.ForeignKeys和EditorTemplateName来获取这些dropdownList @model IEnumerable(GridInForm.Models.Product) - 视图中使用的模型
<div>
@(Html.Kendo().Grid(Model.Products)
.Name("Products")
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Columns(columns =>
{
columns.Bound(p => p.Chk).ClientTemplate("<input type='checkbox' ${ Chk == true ? checked='checked' : ''} disabled />");
columns.Bound(p => p.Person).ClientTemplate("<a href='\\#'>#= Person #</a>").ClientFooterTemplate("Total: #=count#");
columns.ForeignKey(p => p.Account, (System.Collections.IEnumerable)ViewData["TestVDt"], "Value", "Text");
***columns.ForeignKey(p => p.VaryDDList, Model.Products, "ProductID", "Person")
.EditorViewData(new { ProductID = "#=ProductID#" })
.EditorTemplateName("VaryDDL");***
columns.Bound(p => p.ProductID).Hidden();
columns.Bound(p => p.Balance).ClientTemplate("#= kendo.format('{0:c}', Balance) #");
columns.Bound(p => p.Deposit).ClientTemplate("#= kendo.format('{0:c}', Deposit) #");
columns.Bound(p => p.Adjustment).ClientTemplate("#= kendo.format('{0:c}', Adjustment) #").ClientFooterTemplate("Total: #=sum#");
columns.Bound(p => p.NewBalance).ClientTemplate("#= kendo.format('{0:c}', NewBalance) #").ClientTemplate("#= kendo.format('{0:c}', Deposit + Adjustment) #");
})
.DataSource(dataSource => dataSource.Ajax()
.Events(e => e.Change("TestScript"))
.Model(model =>
{
model.Id(p => p.ProductID);
model.Field(p => p.ProductID).Editable(false);
model.Field(p => p.Person).Editable(false);
model.Field(p => p.Balance).Editable(false);
model.Field(p => p.Deposit).Editable(false);
model.Field(p => p.NewBalance).Editable(false);
})
.Aggregates(aggregates =>
{
aggregates.Add(p => p.Person).Count();
aggregates.Add(p => p.Adjustment).Sum();
})
.Batch(true)
.ServerOperation(false)
))
</div>
editortemplatename查看数据(VaryDDL.cshtml)
@(Html.Kendo().DropDownList()
.Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
.DataValueField("Value")
.DataTextField("Text")
.OptionLabel("Select")
.DataSource(dataSource => dataSource
.Read(read => read.Action("ChkProduct", "Home", new { ProductID = ViewData["ProductID"] }))
)
)
上述控制器动作:
public JsonResult ChkProduct(int prodid)
{
if (prodid == 1)
{
List<SelectListItem> Slt1 = new List<SelectListItem>();
SelectListItem sltLst1 = new SelectListItem();
Slt1 = new List<SelectListItem>
{
new SelectListItem { Text="VV1", Value="1" },
new SelectListItem { Text="VV2", Value="2" },
new SelectListItem { Text="VV3", Value="3" }
};
return Json(Slt1.ToList(), JsonRequestBehavior.AllowGet);
}
else
{
List<SelectListItem> Slt2 = new List<SelectListItem>();
Slt2 = new List<SelectListItem>
{
new SelectListItem { Text="VV4", Value="1" },
new SelectListItem { Text="VV5", Value="2" },
new SelectListItem { Text="VV6", Value="3" }
};
return Json(Slt2.ToList(), JsonRequestBehavior.AllowGet);
}
}
请让我知道我做错了什么,还有其他更好的方法 请发布一些代码....谢谢!!