I am using Kendo Grid for Add,Update and Delete functionality. While populating the grid I am giving a list of Data to the grid.
@model OSI.DNAweb.Web.UI.Areas.Administrator.ViewModels.Business.BusinessUserAccountModel
@(Html.Kendo.Grid<Accounts>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.AccountNumber).Title("Account Number");
columns.Bound(p => p.CreditCardNumber).Title("Credit Card Nbr");
columns.Bound(p => p.EnrollTypes).ClientTemplate("#=EnrollTypes.EnrollTypeName#").Title("Type").Width(200);
columns.Bound(p => p.DisplayName).Title("Nickname").Width(200);
columns.Bound(p => p.AsofDate).Title("As Of Date").Format("{0:d}").Width(50);
columns.Command(command => command.Custom("Delete").Click("showDetails")).Width(15);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.Editable(editable =>
{
editable.Mode(GridEditMode.InCell);
editable.DisplayDeleteConfirmation(false);
}
)
.Pageable(page => page.Enabled(false))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.CompanyIdent);
model.Field(p => p.CreditCardNumber).Editable(false);
model.Field(p => p.EnrollTypes).DefaultValue(new EnrollTypes() { EnrollType = "", EnrollTypeName = "Select" });
})
.Create("CreateAccount", "Business")
.ServerOperation(false)
.Read(read => read.Action("GetAccounts", "Business"))
.Update("UpdateAccount", "Business")
.Destroy("DeleteAccount", "Business")
)
)
While Adding,Updating and Deleting it is sending a list of Accounts Class to the respective ActionResult in the controller with the changes. But In my case I want to use BusinessUserAccountModel and pass it to the controller so I can also have some additional properties mentioned in BusinessUserAccountModel class along with Accounts Collection.Please see below the Classes structure:
[Serializable]
public class Accounts
{
#region Properties
public int CompanyIdent { get; set; }
[Required]
[DNAwebCustomValidator(DNAWebValidationDataTypesEnum.AlphaNumeric)]
public string AccountNumber { get; set; }
public string CreditCardNumber { get; set; }
[Required]
[DNAwebCustomValidator(DNAWebValidationDataTypesEnum.AcctNickName)]
public string DisplayName { get; set; }
[DNAwebCustomValidator(DNAWebValidationDataTypesEnum.Date)]
public string AsofDate { get; set; }
[UIHint("AccountTypes"), Required]
public EnrollTypes EnrollTypes { get; set; }
#endregion
}
public class BusinessUserAccountModel : BusinessUserBaseModel
{
public IEnumerable<Accounts> Accounts { get; set; }
public BusinessUserAccountModel(){}
public BusinessUserAccountModel(BusinessData businessData,IEnumerable<Accounts> accts) : base(businessData, BusinessTab.Accounts)
{
Accounts = accts;
}
}
As you see above BusinessUserAccountModel is further inheriting BusinessUserBaseModel. If somehow in my grid CRUD operations if i able to pass BusinessUserAccountModel class along with the Accounts Collection that will solve my problem.
Just for more clarification in my page I have other controls in my page other than grid, so whenever I do CRUD operation in the grid those controls validation should also get fired. Hope you got cleared with my problem.
Thanks,
Nandan