We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Paging grid for detail data related to main view

Thread ID:

Created:

Updated:

Platform:

Replies:

100991 Sep 19,2011 04:36 AM UTC Sep 20,2011 07:21 AM UTC ASP.NET MVC (Classic) 3
loading
Tags: Grid
Administrator [Syncfusion]
Asked On September 19, 2011 04:36 AM UTC

In all the Mvc Grid samples I have seen, the primary view is a list displayed in a grid . In my partucular case, the primary view displays a single record to be edited, Employee, and I need 2 or 3 paging Mvc Grids to show the employee's salary history, a list of employees reporting to him/her, etc.

Below is a simplistic prototype based on NWind Customer and Order tables using Entity Framework. When the user selects a different page in the Orders grid, the "Index(PagingParams args)" method is called. However, that method has no way to determine what the CustomerID is in order to retrieve the Order list for that customer again. (I have hard-coded the customerid to make the app compile). The only parameter passed is of PagingParams type, which does not have this information. If I could somehow pass a second parameter with the CustomerID I could accomplish what I need to.

Do you have an example of how to do this, when the main view is a single record, and I need to have a paging grid displaying some related detail? In my apps that is a fairly common paradigm for maintenance screens.


***** Customer view ********************

@model NWind.Customer
@{
Layout = null;
}

@using (Html.BeginForm("Edit", "Customer", new { @id = ViewBag.CustomerID }))
{






@Html.LabelFor(Model => Model.CustomerID) @Html.TextBoxFor(Model => Model.CustomerID) @Html.LabelFor(Model => Model.CompanyName) @Html.TextBoxFor(Model => Model.CompanyName)


@{Html.RenderPartial( "CustomerOrders", ((List)ViewData["Orders"]));}

}

***** CustomerOrders view ********************

@model List


@{Html.Grid("GridOrders")
.Datasource((List)ViewData["Orders"])
.Caption("Orders")
.EnablePaging()
.PageSettings(page =>
{
page.PageSize(10);
page.AllowPaging(true);
})
.Column(col =>
{
col.Add(a => a.OrderDate).HeaderText("Date");
col.Add(a => a.RequiredDate).HeaderText("Date Required");
col.Add(a => a.ShipCity).HeaderText("City");
col.Add(a => a.ShipCountry).HeaderText("Country");
})
.Height(300)
.AllowResizing(true)
.Render();
}



***** CustomerController ********************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NWind;
using System.Data;
using System.Data.Common;
using System.Data.Objects;
using System.Data.Linq;
using Syncfusion.Mvc.Grid;

namespace SyncfusionMvcApplication1.Controllers
{
public class CustomerController : Controller
{
nwindEntities1 _context = new nwindEntities1();

public ActionResult Index(string customerid)
{
Customer cust = _context.Customers.Where(a => a.CustomerID == customerid)
.FirstOrDefault();
ViewData.Model = cust;
ViewBag.CustomerID = cust.CustomerID;
List orders = _context.Orders.Where(a => a.CustomerID == customerid)
.DefaultIfEmpty().ToList();
ViewData["Orders"] = orders;
return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(PagingParams args)
{
// *** Problem: The customer id needs to be passed here from the view when a new page is selected; hard-coded here so it will compile ***
string customerid = "ERNSH";

List orders = _context.Orders.Where(a => a.CustomerID == customerid)
.DefaultIfEmpty().ToList();
ActionResult actions = orders.GridActions();
return orders.GridActions();
}
}
}




Eswari S [Syncfusion]
Replied On September 19, 2011 07:20 AM UTC

Hi Jim,

Thank you for using Syncfusion products.

Your requirement can be achieved by using the ActionMapper method. ActionMapper method is having optional arguments like ControllerName, ActionName and RouteValues.

Please refer to the following code snippets:

[ASPX]

@{ Html.Syncfusion().Grid("SampleGrid")

. . .
.Mappers(map=>{
map.Action("Index", new { CustomerID = "VINET" }); // Index is the Action for paging,sorting,etc. CustomerID is the route value

map.InsertAction("AddOrder")
.SaveAction("OrderSave")
.DeleteAction("DeleteOrder") // These are the action mappers for editing
.ExportExcelAction("ExcelExport"); // Action mappers for exporting

})
. . . .
.Render();
}

[Controller]

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(PagingParams args, string CustomerID)
{
IEnumerable data = new NorthwindDataContext().Orders.Where(c => c.CustomerID == CustomerID).ToList();
return data.GridActions();

}

For your convenience ,we have prepared the sample and the same can be downloaded from the following link :

Sample490477057.zip

Please try this and let us know if you need any further assistance.

Regards,
Eswari.S




Administrator [Syncfusion]
Replied On September 19, 2011 05:55 PM UTC

Thank you again! Syncfusion has hands down the best tech support of any .Net product I have ever purchased.


Eswari S [Syncfusion]
Replied On September 20, 2011 07:21 AM UTC

Hi Jim,

Thanks for the update.

Happy to hear that you have everything working . Do not hesitate to update if you have any questions.

Regards,
Eswari.S


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;