0

我有一个剑道网格视图,其中一列是布尔值。在该列中,出现的信息标记为“真”(表示 1 或真)、“假”(表示 0 或假)或空白(表示空)。这看起来不是很专业,我正在尝试将网格中的这些值更改为显示为是、否或无(分别)。我用来尝试实现这一点的代码是:

模型:

namespace MvcApplication.Models
{
    public class Companies
    {

        public string IsAdmitted { get; set; }

控制器:

    [HttpPost]
    public ActionResult Companies_Read([DataSourceRequest] DataSourceRequest request)
    {
        using (var companydata = new CompaniesDataContext())
        {
            List<Companies> model = new List<Companies>();
            var companylist = companydata.Companies_JBs.Select(s => s).ToList();
            foreach (var h in companylist)
            {
                Companies x = new Companies();
                x.IsAdmitted = h.IsAdmitted == (bool)true ? x.IsAdmitted = "Yes" : h.IsAdmitted == (bool)false ? x.IsAdmitted = "No" : x.IsAdmitted = "Null";
                model.Add(x);
            }

            return Json(companydata.Companies_JBs.ToDataSourceResult(request));
        }
    }

看法:

@(Html.Kendo().Grid(Model)
    .Name("Company_Grid")
    .Columns(columns =>
        {
            columns.Bound(o => o.IsAdmitted).Title("Admitted:").Width(95);
            columns.Command(command => { command.Edit(); command.Destroy(); });
         }
    )
    .ToolBar(toolbar => toolbar.Create().Text("Add a Company"))
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("Companies"))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model => model.Id(o => o.ID))
        .Create(update => update.Action("Companies_Create", "Home"))
        .Update(update => update.Action("Companies_Update", "Home"))
        .Destroy(update => update.Action("Companies_Destroy", "Home"))
        .Read(read => read.Action("Companies_Read", "Home"))
    )
)

当我放置断点并检查值时,它表示 IsAdmitted 字段项标记为是、否或无(取决于它们在我的 sql 数据库中的值)。但是,在网格本身中,它们仍被标记为 true、false 或空白。我的问题是什么,或者有更好的方法吗?

4

1 回答 1

1

你为什么要回来Json(companydata.Companies_JBs.ToDataSourceResult(request));

你必须返回model。所以,控制器方法的返回语句应该是

return Json(model.ToDataSourceResult(request));
于 2013-07-11T16:22:40.627 回答