mvc gridview with code - asp.net-mvc

how to get a gridview in model view control,how to edit,delete the gridview with source code

Telerik has a great grid that's free (open source) for MVC. You can view it here, and the download is on their web site.
http://demos.telerik.com/aspnet-mvc/grid

You don't have access to ASP.NET controls in ASP.NET MVC, well not with the postback and viewstate stuff atleast.
However, you can create a nice GridView with ajax edit/delete capabilities by using something like jqGrid and a little code. Here are a couple of blog posts to get you started :
Full Walkthrough of MvcContrib Grid with jQuery Data table
Using jQuery Grid With ASP.NET MVC
Hope that helps

Paginated List
Divides IQueryable source of any type on pages and returns items for current page. Useful for creating custom gridviews and pagers in C#, ASP.NET WebForms or MVC. Althought this code is used for pagnition, there is example on how to create Gridview with paging. Shouldn't be too hard to create CRUD actions from it.

Related

MVC grid with sorting, paging and searching

Does anyone know any article or tutorial how to create nice grid for mvc with functions like columns sorting, paging and searching for items inside the grid?
Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application
Now the best option is Grid.MVC . which you can download from Nuget.
Website :https://gridmvc.codeplex.com/
Demo :http://gridmvc.azurewebsites.net/
Tutorial :http://www.codeproject.com/Tips/597253/Using-the-Grid-MVC-in-ASP-NET-MVC

Existing MVC website - integrating Telerik MVC Grid to use ServerSideEditing

I have an existing MVC site, built some years back, and I am now removing all my custom grid code with Telerik's MVC Grid.
I wish to utilise the ServerSide editing but the examples show the SourceCodeFile scaffolding on a single control actionresult reference by a single MVC grid in a single view.
My issue is that I have mulitple MVC grids called by renderpartial in a single view with a single controller actionresult. I cannot have multiple scaffolding on the single actionresult.
I therefore need some assistance on thinking this through as I only visit this project once in a while and I am not constantly building in MVC so do not totally know all my options.
Also posted on the Telerik forums at: http://www.telerik.com/community/forums/aspnet-mvc/grid/existing-mvc-website---integrating-telerik-mvc-grid-to-use-serversideediting.aspx
If you look here, you will see that for each grid, you can specify the action/controller to execute for each action (select, insert, update, delete). If I am understanding you correctly, you should then be able to manage editing of each grid server side, correct?

Why should I not use an ASP.NET datagrid control in MVC

I don't want to make this into a "which is better... MVC or WebForms" type of question. Im sure that has been asked a bunch of times here already.
My Question: If I am building a MVC web project, why should I not use an ASP.NET datagrid control on one of my "Views" .aspx pages?
The control relies on Viewstate which isn't available in MVC. In addition, all the behavior is predicated on the WebForms event and postback model which you'd have to recreate in MVC to get them to work. You could search for alternate, MVC-friendly grids (perhaps jQuery-based). I know that Telerik has released a set of MVC controls under open source that might be helpful to you.
you can't use web forms controls in MVC because they depend on view state. Use the data grid of the Mvc Controls toolkit instead. It has paging, insert delete and update capabilities and it is completely templated (you can shap it as you like). Look at it here
The datagrid control depends on postback events which does not fit into the MVC way of thinking (the postback goes to the page code behind rather than the controller). You could use one without any postback features, i believe, but you may as well craft something directly.
Because the ASP.NET DataGrid / GridView has too much responsibility to fit into the MVC pattern. You'll have to add some code-behind to your view to databind the grid - code that belongs in the controller.
Anything that uses postback won't work with MVC, so the DataGrids paging and sorting won't be any good to you. So there really isn't any benefit to using it.
If you're looking for a flexible grid 'control' (MVC prefers the term HTML Helper), the MvcContrib grid is pretty good.

Why do you return the image generated by a Chart control, rather than use it in a view in ASP.NET MVC?

Why can't you use the Chart control directly in views? Why do you have to return the image generated?
Although there are ways to get WebForms working with MVC, however, fundamentally WebForms controls cannot work in ASP.NET MVC Views as 'WebForms Templates'. Clue is in the name.. APS.NET MVC uses the WebForms as templates, so you don't get the full page life-cycle events and so on in ASP.NET MVC views.
If you don't want to generate images, another option is to use a javascript based graph utility (based on jQuery).

ASP.net MVC Paging

I have textboxes loaded with data on my ASP.NET MVC page. If the user clicks the Next button I need to load the textboxes with the relevant data. Similarly I have Next, Prev and Last buttons for record navigation. I have no idea on how to implement this. If it is JQuery how I can implement it? How do I implement it in ASP.NET MVC?
The good news is that there is a complete example of this in the Nerddinner ASP.NET MVC Walkthrough (pg 118-127).
(source: barnesandnoble.com)
I also recommend the book that this is the sample chapter of: Professional ASP.NET MVC 1.0 by Wrox Press.
change your model to implement a PagedList and then bind the each item in the result to a textbox, this can be done in Ajax using Jquery too

Resources