Asp.net mvc 4 MVC | KendoUI Grid |在单击更新时无法在下拉列表中查看新选择的值
我在剑道UI网格中有一个下拉列表,标记如下 视图Asp.net mvc 4 MVC | KendoUI Grid |在单击更新时无法在下拉列表中查看新选择的值,asp.net-mvc-4,telerik-mvc,Asp.net Mvc 4,Telerik Mvc,我在剑道UI网格中有一个下拉列表,标记如下 视图 @(Html.Kendo().Grid<MMM.Lumos.Web.ViewModels.TestPointViewModel>() .Name("TestPoint") .DataSource(dataSource => dataSource.Ajax() .Model(model => { model.Id(m => m.TestPoint
@(Html.Kendo().Grid<MMM.Lumos.Web.ViewModels.TestPointViewModel>()
.Name("TestPoint")
.DataSource(dataSource => dataSource.Ajax()
.Model(model =>
{
model.Id(m => m.TestPointId);
})
.Create(update => update.Action("CreateTestPoint", "TestPoint"))
.Read(read => read.Action("ReadTestPoints", "TestPoint"))
.Update(up => up.Action("UpdateTestPoint", "TestPoint"))
.Destroy(update => update.Action("DeleteTestPoint", "TestPoint"))
)
.Columns(columns =>
{
columns.Bound(c => c.TestPointId).Width(200).Visible(false);
columns.Bound(c => c.TestPointName).Width(200);
columns.Bound(c => c.TestPointMethodId).EditorTemplateName("TestPointMethodDDL").Title("Test Point Method").ClientTemplate("#= TestPointMethodName#"); //TestPointMethodDDL : Name of the .cshtml file placed in the '~/Views/Shared/EditorTemplate'
columns.Bound(c => c.PassThreshold).Width(100);
columns.Bound(c => c.FailThreshold).Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(500);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(ed => ed.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
.Sortable()
.Events(events =>
{
events.Save("TestPointGrid_Save");
})
)
查看下拉列表
@using System.Collections
@model System.String
@(Html.Kendo().DropDownList()
//This Kendo drop down list gets its data from the 'ViewBag.TestPointMethods' dynamic property,
//so you will have to add this to the main page's action as done in the below line.
.BindTo((IEnumerable)ViewBag.TestPointMethods)
////Optional Default value to be added in the dropdown list
//.OptionLabel("- Select - ")
//The value is taken from the 'TestPointMethodID' property of TestPointMethod Model
.DataValueField("TestPointMethodId")
//The text is taken from the 'TestPointMethodName' property of TestPointMethod Model
.DataTextField("TestPointMethodName")
//"Name("TestPointMethodId")".
//The name helper should have a name that is exactly like the column the drop down list is bound to as shown in the grid.
//The column is bound to "TestPointMethodId" so the drop down list should have a name "TestPointMethodId".
.Name("TestPointMethodId")
.Events(e => e.Change("onDropDownChanged"))
)
型号
namespace test.test1.Web.Models
{
using System;
using System.Collections.Generic;
public partial class TestPoint
{
public int TestPointId { get; set; }
public string TestPointName { get; set; }
public Nullable<int> TestPointMethodId { get; set; }
public Nullable<decimal> PassThreshold { get; set; }
public Nullable<decimal> FailThreshold { get; set; }
public Nullable<int> CreatedBy { get; set; }
public Nullable<System.DateTime> CreatedOn { get; set; }
public Nullable<int> ModifiedBy { get; set; }
public Nullable<System.DateTime> ModifiedOn { get; set; }
public virtual TestPointMethod TestPointMethod { get; set; }
}
}
public class TestPointViewModel
{
public int TestPointId { get; set; }
public string TestPointName { get; set; }
public int? TestPointMethodId { get; set; }
public decimal PassThreshold { get; set; }
public decimal FailThreshold { get; set; }
public string TestPointMethodName { get; set; }
}
在上面的示例中,我能够将数据保存在数据库中。但单击更新后,测试点方法列中的文本仍然显示选定的旧值。
刷新页面时,网格将显示数据库中的条目
如果有人能解决这个问题,请告诉我。在过去3天中,我一直在寻找这一点。可以使用以下方法之一,根据dropdownlist中的选择更新文本属性: 使用“保存”事件更新模型文本值:
function TestPointGrid_Save(e) {
var dropdownlist = $("#TestPointMethodId").data("kendoDropDownList");
e.model.TestPointMethodName = dropdownlist.text();
}
或
更新值和显示正确文本的替代方法是使用演示中演示的或对象 只是补充一下,我在网格中使用内联编辑模式。在特定行中单击“更新”按钮后,条目将保存在数据库中,但下拉选择值(下拉列表中的文本)显示旧值。但是当页面被刷新时,新的值显示为displayedGuys,我为上面的问题找到了一个解决方案,以防万一,如果它对某人有帮助的话。可以使用以下方法之一根据dropdownlist中的选择更新text属性:使用save事件更新模型文本值:函数TestPointGrid_save(e){var dropdownlist=$(“#TestPointMethodId”).data(“kendoDropDownList”);e.model.TestPointMethodName=dropdownlist.text();}另一种方法是从服务器返回带有更新文本的项:public ActionResult UpdateTestPoint([DataSourceRequest]DataSourceRequest,TestPointViewModel TestPoint){……TestPoint.TestPointMethodName=UpdatedName;返回Json(new[]{TestPoint}.ToDataSourceResult(request,ModelState));}
function TestPointGrid_Save(e) {
var dropdownlist = $("#TestPointMethodId").data("kendoDropDownList");
e.model.TestPointMethodName = dropdownlist.text();
}
public ActionResult UpdateTestPoint([DataSourceRequest] DataSourceRequest request, TestPointViewModel TestPoint)
{
...
TestPoint.TestPointMethodName = UpdatedName;
return Json(new[] { TestPoint }.ToDataSourceResult(request, ModelState));
}