Hi,
I try to create a generic grid which will map severals tables and I'll be able to modify the content of those table by only one grid but I've some trubble.
Idea is having only one grid which will take an object like and load all the porperties automatically. We will be able to save data by save button. I took the example you have in your website which is Basic Edit of grid.
I prepared an example at I join it to you with this mail. You have only two pages
HomeController:
public ActionResult SaveGenericData()
This function save the data modified in grid, this I want to it in a generic way
public ActionResult GetGenericData()
This function send a Queryable object, this method I would send a generic data
Index.html:
You will find the grid:
@model IQueryable<TestCountry>
this I want it to take a generic object
@(Html.Infragistics()
.Grid(Model)
.ID("Grid")
.PrimaryKey("CountryId")
Here it takes a primary key, it should be a dynamic key calculated from generic class
Thank you for your help
Hello cem ozbas,
Thank you for posting in our forums!
I recommend using the MVC ViewBag to achieve this. You can assign the values you want to reference in the View from the Controller.
This lets you do something like:
HomeController.cs:
ViewBag.GridPK = "CountryId";
Index.cshtml:
@(Html.Infragistics() .Grid(Model) .ID("Grid") .PrimaryKey(ViewBag.GridPK)
If you have any further questions or concerns with this, please let me know.
Hi Michael,
Thank you for your answer. You have just answered only %1 of what I needed. If you read my question carefully you will see it's more complicate and it is not that easy (for me). I'll try to explain a little bit more,
I have many table in my database (I use only two entites for this example)
TestCountry
CountryCode
CountryName
TestProduct
ProductCode
ProductName
...
... many other table
I want to be able to load each table on the screen by using only one grid. This grid will read all the properties of the entity and show all in the screen. Then I will be able to modify them by using standard functions of grid.
We are also using your products for on of our projet with winform and there, you can just give an entity and modify it directly without any trubble. I wonder if you have any possibilities to pass an entity and the grid do the rest.
I prepared an mvc solution that you will find it in the page. Please try to produce an example on this solution than it will be easier to understand each other.
Thank you
Hi cem ozbas,
I was not able to get your sample running for some reason, so I have created a new sample based on it.
I set up a sample using your entities and created a derived CustomGridModel class. This class handles the initialization of the Updating feature and also handles the DataSource property which will set the grid's DataSource and determine the PrimaryKey that should be used using some Reflection.
This means all you need to do is create the CustomGridModel and set the DataSource. You may also need to handle some additional logic for saving the grid's data to the DataBase but that depends on how you want to handle that. You can find more information on that in our documentation here.
In the sample, the same CustomGridModel class is used to display different data from the TestCountries and TestProducts. I have attached my sample that demonstrates how this can be done.
If you need further assistance with this, please let me know.