我有一个telerik网格, 当我编辑一行时: 但如果我按下更新按钮甚至取消(观看中间栏):
这是宣言:
<%= Html.Telerik().Grid<AlefTech.HumanResource.WebModule.ViewDto.MaritialStatusItemEditDto>(Model)
.Name("Grid")
.DataKeys(keys => { keys.Add(c => c.MaritialStatusItemID); keys.Add(k => k.Index); })
.Columns(columns =>
{
//columns.Bound(m => m.MaritialStatusItemID).Visible(false);
columns.Bound(m => m.Index).Title("").Sortable(false).Width(0);
columns.Bound(m => m.Name);
//columns.Bound(m => m.Brithdate).Width(130).Format("{0:d}");
//columns.Bound(m => m.Gender);
columns.Bound(m => m.MaritialStatusItemType);
//columns.Bound(m => m.Notes);
//columns.Bound(m => m.Status);
//columns.Bound(m => m.CreationDate);
//columns.Bound(m => m.ItemGuid);//.ClientTemplate("<input type='hidden' value='<#ItemGuid#>' name='ItemGuid' id='WorkerID'>");
columns.Command(command => { command.Edit(); command.Delete(); });
})
//.ClientEvents(cfg => cfg.OnDataBound("onRowDataBound"))
.ToolBar(t => t.Insert())
.DataBinding(d => d.Ajax()
.Select("MartialStatusGridSelect", "Worker")
.Insert("MartialStatusGridInsert", "Worker")
.Update("MartialStatusGridUpdate", "Worker")
.Delete("MartialStatusGridDelete", "Worker"))
.Scrollable()
.Editable(editing => editing.Enabled(true))
.Sortable()
.HtmlAttributes(new { @class = "t-grid-rtl", @hegiht = "450px" })
.Pageable()
%>
和模型:
public class MaritialStatusItem : BaseEntity
{
[StringLength(50)]
[Required]
public virtual string Name { get; set; }
[UIHint("MaritialStatusEnum")]
public virtual MilitaryStatusEnum MaritialStatusItemType { get; set; }
}
显示模板MaritialStatusEnum.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%=((MilitaryStatusEnum)Model == .MilitaryStatusEnum.Serving)? "Serving" : "Finished"
%>
编辑模板
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<AlefTech.HumanResource.Core.MartialStatusEnum>" %>
<%=Html.DropDownList("MartialStatus", new SelectListItem[] { new SelectListItem { Text = "Serving", Value = "0" }, new SelectListItem { Text = "Finished", Value = "1" } }) %>
任何想法为什么会发生这种情况?
答案 0 :(得分:1)
好吧,我用这个topic中提到的方式解决了问题 如下:
columns.Bound(m => m.MaritialStatusItemType).ClientTemplate("<#= maritialStatusItemEnum[MaritialStatusItemType] #>");
.
.
.
<script type="text/javascript">
var maritialStatusItemEnum = ["Single person", "Married Person", "Divorced Person", "Widowed"];
</script>
并注意这是Enum属性的解决方案,但是如果你有一个复杂的对象,你应该考虑另一个解决方案。