I am using MVC.In my website i need to show a gridview with paging that shows datafrom database.Could you please help me steps to create a gridview like this .
@{ UMMbr.Model.SOTI product = new UMMbr.Model.SOTI(); var db = ApplicationContext.Current.DatabaseContext.Database; // Fetch a collection of contacts from the db. var listOfContacs = db.Fetch<UMMbr.Model.SOTI>(new Umbraco.Core.Persistence.Sql().Select("*").From("SOTI"));
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
@{
var FirstParam= (string)ViewData["FirstParam"];
var SecondParam= (bool)ViewData["SecondParam"];
}
This partial view is strongly typed and is passing the current page as the Model,
so you can access properites like this:
GridView with paging
I am using MVC.In my website i need to show a gridview with paging that shows datafrom database.Could you please help me steps to create a gridview like this .
Hi Deepa,
kindly look at below url , this is the good example of mcv grid with paging
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application
Hope it will help you.
Regards,
Mehul Gajjar.
I need the steps for creating this grid in Umbraco.Is it need to create a webgrid in a partial view
Hi Deepa,
yes you need to create a webgrid in a partial view.
and if you need this in umbraco back office then you have to make a custom property editor.
Regards,
Mehul Gajjar.
This is my partial view
@{
UMMbr.Model.SOTI product = new UMMbr.Model.SOTI();
var db = ApplicationContext.Current.DatabaseContext.Database;
// Fetch a collection of contacts from the db.
var listOfContacs = db.Fetch<UMMbr.Model.SOTI>(new Umbraco.Core.Persistence.Sql().Select("*").From("SOTI"));
}
@{
var grid = new WebGrid(listOfContacs, canPage: true, rowsPerPage: 2, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Title", "Title"),
grid.Column("Quarter", " Quarter"),
grid.Column("Summary", "Summary", style: "description"),
grid.Column("Link", "Link")
))
@if (grid.HasSelection)
{
product = (UMMbr.Model.SOTI)grid.Rows[grid.SelectedIndex].Value;
<b>Id</b> @product.Title<br />
<b>Name</b> @product.Quarter<br />
<b>Description</b> @product.Summary<br />
<b>Quantity</b> @product.Link<br />
}
But paging is not working .
How can i get data from controller to webgrid?.
Hi Deepa,
For getting a data from controller you have to pass model to your partial view at the time of calling
you can access your model data after inherit using
@import YOURNAME_SPACE.YOUR_MODEL
in your partial view.Also see below example
https://our.umbraco.org/documentation/Reference/Mvc/partial-views
https://our.umbraco.org/documentation/Reference/Templating/Mvc/child-actions#RenderingaChildAction
You can pass parameters in your partial view like this:
Partial View Macro
Partial View
This partial view is strongly typed and is passing the current page as the Model, so you can access properites like this:
Hope that's helpful
Regards
Mehul Gajjar.
is working on a reply...