This question is locked. New answers and comments are not allowed.
I have a details page for a Client with a Grid of Contacts listed. So using Ajax how do I pass the clientID to the _AjaxCreate method.
I am using a partial view for the Grid:
I am using a partial view for the Grid:
@ModelType IEnumerable(Of ClientSites30.ViewModels.ContactGridViewModel)
@Html.Telerik.Grid(Model).Name("ContactsGrid").ToolBar(Function(commands) commands.Insert()).DataKeys(Function(keys) {keys.Add(Function(c) c.ID)}).DataBinding(Function(dataBinding) dataBinding.Ajax().Select("_AjaxBinding", "Contact").Insert("_AjaxCreate", "Contact").Update("_AjaxEdit", "Contact").Delete("Delete", "Contact")).Columns(Function(columns) {columns.Bound(Function(c) c.FirstName), columns.Bound(Function(c) c.LastName), columns.Bound(Function(c) c.Email), columns.Bound(Function(c) c.PhoneNumber), columns.Command(Function(commands) {commands.Edit(), commands.Delete()}).Width(200)}).Pageable().Sortable()
And for the _AjaxCreate I would want to use something like this:
<HttpPost()> _
<GridAction()> _
Function _AjaxCreate(ByVal newContact As Contact, ByVal clientID As Integer) As ActionResult
Try
Dim client As Client = db.Clients.Find(clientID)
newContact.Client = client
If ModelState.IsValid Then
db.Contacts.Add(newContact)
db.SaveChanges()
End If
Catch ex As Exception
ModelState.AddModelError("", "CreateFailure, see inner exception")
End Try
Dim contacts = From c In db.Contacts
Where c.Client.ID = clientID
Order By c.LastName Ascending, c.FirstName Ascending
Select New ContactGridViewModel With {.ID = c.ID, .ClientID = c.ClientID, .FirstName = c.FirstName, .LastName = c.LastName, .PhoneNumber = c.PhoneNumber, .Email = c.Email}
Return View(New GridModel(contacts.ToList))
End Function
So any suggestions on how I can get this to work would be greatly appreciated.