我正在使用 mvc4 并有一个启用了编辑模式的 Telerik 控制网格。编辑模式是“PopUp”,这意味着单击编辑按钮时,应该出现一个覆盖层,其中一些字段填充在文本框中,一些字段填充在标签中。
问题是字段值未在标签中呈现。字段值呈现在文本框中进行编辑,这很好。
查看模型
namespace Admin.Models
{
public class ViewModel
{
public int Id{ get; set; }
[DataType(DataType.Text)]
public string Name { get; set; }
}
}
.cshtml 文件
@model Admin.Models.ViewModel
<div>
<div class="editor-label">
@Html.LabelFor(model => model.Id)
</div>
<div class="editor-field">
@Model.Id **Does not work,always return 0, should return value 1,2,...**
@Html.DisplayFor(model => model.Id) **Does not work,always return 0, should return value 1,2,...**
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
</div>
</div>
Controller 代码
[GridAction]
public ActionResult Index()
{
IList<ViewModel> viewModels = GetModelItems();
return View(new GridModel
{
Data = viewModels
});
}
最佳答案
Teleric 似乎不支持 DisplayFor 编辑模板。 在这个论坛帖子中,他们确认了这一点http://www.telerik.com/community/forums/aspnet-mvc/grid/clajax-databinding-client-editing.aspx#1906385
关于telerik - @Model 或 @Html.DisplayFor 在 mvc 4 的编辑器模板中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10656638/