BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
public class AdminController : Controller
{
private IChapterRepository repositoryChapter;
private IBranchRepository repositoryBranch;
public AdminController(IChapterRepository chapterRepository, IBranchRepository branchRepository)
{
this.repositoryChapter = chapterRepository;
this.repositoryBranch = branchRepository;
}
/// <summary>
/// Used for rendering the grid initially.
/// </summary>
/// <returns>Veiw page, it displays the Grid</returns>
public ActionResult Chapters()
{
ViewData[
"BranchCode"] = BranchList;
var data = repositoryChapter.Chapters.ToList();
return View(data);
}
public IEnumerable<SelectListItem> BranchList
{
get
{
List<SelectListItem> type = new List<SelectListItem>();
var branches = repositoryBranch.Branches;
foreach (var branch in branches)
{
type.Add(
new SelectListItem
{
Text = branch.BranchName,
Value = branch.BranchCode
});
}
return type;
}
}
....
CODE AT THE CSHTML
.Datasource(Model)
.ActionMode(Syncfusion.Mvc.Grid.
ActionMode.Server)
.Caption(
"Chapters").Scrolling(s => s.Height(300))
.Column(column =>
{
column.Add(c => c.ChapterId).HeaderText(
"Chapter ID").TextAlign(Syncfusion.Mvc.Grid.TextAlignment.Left).Width(100);
column.Add(c => c.ChapterName).HeaderText(
"Chapter Name").TextAlign( Syncfusion.Mvc.Grid.TextAlignment.Left).Width(100);
column.Add(c => c.ChapterFullName).HeaderText(
"Chapter Full Name").Width(130);
column.Add(c => c.BranchCode).HeaderText(
"Branch").CellEditType(CellEditType.DropdownEdit).Width(130).DropDownDataSource((System.Collections.IEnumerable)ViewData["BranchCode"]);
column.Add(c => c.EmailAddress).HeaderText(
"Email Address").Width(110);
})
.EnablePaging()
.EnableSorting()
.AutoFormat(Syncfusion.Mvc.Shared.
Skins.Marble)
.Caption(
"Chapters")
.ToolBar(tools =>
{
tools.Add(
GridToolBarItems.AddNew)
.Add(
GridToolBarItems.Edit)
.Add(
GridToolBarItems.Delete)
.Add(
GridToolBarItems.Update)
.Add(
GridToolBarItems.Cancel);
})
.Mappers(mapper =>
{
mapper.InsertAction(
"AddChapter")
.SaveAction(
"ChapterSave")
.DeleteAction(
"DeleteChapter");
})
.Editing(edit =>
{
edit.AllowEdit(
true)
.AllowNew(
true)
.AllowDelete(
true);
edit.PrimaryKey(key => key.Add(c => c.ChapterId));
})
)
PLEASE CAN YOU HELP, BEING STUCK FOR 4 DAYS
Hi
Joseph,
Thanks for your interest in Syncfusion products.
I have created a sample based on your code snippet. Could you use
that sample and reproduce the error if any. We have resolved your issue by
giving the name of the dataTextField and dataValueField in
DropDownDataSource method.
Please refer the below online documentation link:
http://help.syncfusion.com/UG/ASP.NET%20MVC/Grid/documents/databindingsupportfo.htm
For your convenience we have attached a sample and screenshot.
Could you use that sample and get back to us if you have any queries.
Let us know if you have any concerns.
Regards,
Abdul Matin M