【发布时间】:2012-01-21 21:03:11
【问题描述】:
我正在尝试使用 Ajax 编辑实现 Telerik MVC 网格。基本上,它是一类组,每个组都属于一个组织,我需要在编辑模式下显示一个下拉列表,其中包含可供选择的可能组织。
我已按照教程和此论坛进行操作,但无法使其正常工作。
这是我的代码:
型号:
Partial Public Class hdmtGROUP
<ScaffoldColumn(False)>
Public Property gID As Integer
Public Property gORG As Integer
'Dropdownlist.
<UIHint("_OrgDropDownListPartial"), Required()>
Public Property Organisation As String
<DisplayName("Name")>
<Required(ErrorMessage:="A {0} is required.")>
<StringLength(120, ErrorMessage:="{0} is too long.")>
Public Property gNAME As String
<DisplayName("Description")>
<Required(ErrorMessage:="A {0} is required.")>
<StringLength(2000, ErrorMessage:="{0} is too long.")>
Public Property gDESC As String
Private _hdmtORG As hdmtORG
Public Overridable Property hdmtORG As hdmtORG
Friend Get
Return _hdmtORG
End Get
Set(ByVal value As hdmtORG)
_hdmtORG = value
End Set
End Property
End Class
Partial Public Class Organisation
Public Id As Integer
Public Name As String
End Class
我的控制器:
Public Class GroupController
Inherits System.Web.Mvc.Controller
Private unitOfWork As UnitOfWork = New UnitOfWork()
Function Index() As ViewResult
PopulateOrgsDropDownList()
Return View(Me.unitOfWork.GroupRepository.Get())
End Function
<GridAction()>
Public Function AjaxSelect() As ActionResult
Return View(New GridModel(Me.unitOfWork.GroupRepository.Get()))
End Function
Private Sub PopulateOrgsDropDownList(Optional selectedOrg As Object = Nothing)
ViewData("orgs") = Me.unitOfWork.OrgRepository.Get() _
.Select(Function(o) New With {.Id = o.orgID, .Name =o.orgNAME}) _
.OrderBy(Function(o) o.Name)
End Sub
我的看法:
'declare the grid and enable features
Dim grid = Html.Telerik().Grid(Model) _
.Name("Grid") _
.DataKeys(Function(k) k.Add(Function(g) g.gID)) _
.Pageable() _
.Sortable() _
.Filterable() _
.ToolBar(Function(t) t.Insert()) _
.DataBinding(Function(dataBind) dataBind.Ajax() _
.Select("AjaxSelect", "Group") _
.Insert("Create", "Group") _
.Update("Edit", "Group") _
.Delete("Delete", "Group"))
'Add grid columns
grid.Columns(Function(columns) columns.Bound(Function(g) g.gNAME).Width(200))
grid.Columns(Function(columns) columns.Bound(Function(g) g.gDESC).Width(200))
grid.Columns(Function(columns) columns.Bound(Function(g) g.Organisation).Width(200))
grid.Columns(Function(columns) columns.Command(Function(s) {s.Edit().ButtonType(GridButtonType.BareImage), s.Delete.ButtonType(GridButtonType.BareImage)}).Width(65))
'Render the grid
grid.Render()
function onEdit(e) {
$(e.form).find('#Organisation').data('tDropDownList').select(function (dataItem) {
return dataItem.Text == e.dataItem['Organisation'];
});
}
以及局部视图:
@imports System.Collections
@imports Telerik.Web.Mvc.UI
@(Html.Telerik().DropDownList() _
.Name("Organisation") _
.BindTo(New SelectList(DirectCast(ViewData("orgs"), IEnumerable), "Id", "Name")))
@
如果有任何帮助,我将不胜感激。
非常感谢。
【问题讨论】:
标签: asp.net-mvc-3 telerik-grid telerik-mvc