编辑 Telerik 网格下拉列表时为空模型
我有一个 Telerik 网格,在编辑时显示下拉菜单。问题是,我无法在下拉列表中设置所选值 - 它显示为 null Reference。这是代码:
Controller
public ActionResult MultipleGm(long Id)
{
LoadGmData(Id);
List<gm_select> LoadedGm = GmFunctions.GetGms(Id);
return View("Gm/MultipleGm", LoadedGm);
}
public void LoadGameData(long Id)
{
ViewBag.Tms = GmFunctions.GetTms(Id);
}
Model
public partial class gm_select
{
[UIHint("NameID")]
public name_id { get; set; }
}
public partial class name_id
{
public long id;
public string name;
}
View
@model List<gm_select>
@(Html.Telerik().Grid(Model)
.Name("Names")
.Columns(columns =>
{
columns.Bound(o => o.name_id);
})
DisplayTemplate
@model name_id
@Model.name
EditorTemplate
@model name_id
@(Html.Telerik().DropDownList()
.Name("DropDownList")
.BindTo(new SelectList((IEnumerable) ViewBag.Teams,"id","name", Model.name))
)
问题出在代码 Model.name 中,我不知道这是空的。如果我将代码更改为
@model name_id
@(Html.Telerik().DropDownList()
.Name("DropDownList")
.BindTo(new SelectList((IEnumerable) ViewBag.Tms,"id","name"))
)
它可以工作,但是在编辑时它不会显示正确的所选项目。
欢迎任何帮助,谢谢。
I have a telerik grid that shows a drop-down when editing. The problem is, that I can't set the selected value on the drop-down - it says null Reference. Here is the code:
Controller
public ActionResult MultipleGm(long Id)
{
LoadGmData(Id);
List<gm_select> LoadedGm = GmFunctions.GetGms(Id);
return View("Gm/MultipleGm", LoadedGm);
}
public void LoadGameData(long Id)
{
ViewBag.Tms = GmFunctions.GetTms(Id);
}
Model
public partial class gm_select
{
[UIHint("NameID")]
public name_id { get; set; }
}
public partial class name_id
{
public long id;
public string name;
}
View
@model List<gm_select>
@(Html.Telerik().Grid(Model)
.Name("Names")
.Columns(columns =>
{
columns.Bound(o => o.name_id);
})
DisplayTemplate
@model name_id
@Model.name
EditorTemplate
@model name_id
@(Html.Telerik().DropDownList()
.Name("DropDownList")
.BindTo(new SelectList((IEnumerable) ViewBag.Teams,"id","name", Model.name))
)
The problem is here in the code Model.name, I don't know way this is null. If I change the code to
@model name_id
@(Html.Telerik().DropDownList()
.Name("DropDownList")
.BindTo(new SelectList((IEnumerable) ViewBag.Tms,"id","name"))
)
It works, but when editing it doesn't show the correct selected item.
Any help is welcome, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看以下显示类似设置的在线示例:
如果它们没有帮助,请考虑在 Telerik 论坛中打开论坛线程并发送一个简短的示例应用程序。
You can check the following online examples which show a similar setup:
If they don't help consider opening a forum thread in the Telerik forums and sending a short sample application.