Existing MVC website - integrating Telerik MVC Grid to use ServerSideEditing - asp.net-mvc

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?

Related

asp.net mvc custom template for application forms and page

everyone, I'm really new with asp.net mvc
I have given this new task that converting existing application using asp.net webform into asp.net mvc
This application have basically have 3 type template form:
Grid Template (include the navigation such paging and search, and input/view form/panel shown after click, can be below or hide the grid)
Process Template (Grid with check box on each item to process)
Non-Grid Template (just input form, usually used for application parameter form)
This application also has some template pages, but basically this template page is combining just 1 template form or more (can be same template form), e.g parameter application form or sales order application (master and detail). The page can also has many detail show in tabs.
How do I achieve this templates using asp.net mvc as efficient as possible rather than just create new form and copy-paste from the other form.
I mean to minimalize the same code I have to write rather the specific thing that differentiate the form purpose, e.g the code just show the input form after click item.
Can anyone show me how I can do it or solution that came near to what I need?
Any link to tutorial, step by step, or anything?
Or if there any reasons I can't/shouldn't do it with asp.net mvc and what is the best way?
Thanks in advance and sorry if there are any mistakes in my words.
Editor/Display templates
They are mostly used for edit/display forms such as editing/displaying user profile data form, etc. Kind of like your Non-Grid Template. You can create Object templates, place them in the corresponding folders of the solution and they will be automatically every time you render your model via Html.EditorForModel() or Html.DisplayForModel helpers. Here is a good article to start with ASP.NET MVC 2 Templates, Part 4: Custom Object Templates
Shared views
I'm not sure what your Process template looks like but it seems it's a fixed number column grid like a one column with chackboxes and one more column with names of the items to process. In this case you'd better create an interface and a shared view. Then you can use the interface to map your view model to and render it with your shared view via Html.Partial helper.
Html helpers
For more advance grid templates just use a grid template, there are a lot of online, personelly I prefer Grid helper from MvcContrib library.
Two combine different templates within a single page use layout, sections and again shared view. Here is a good video about how to create and use them Asp Net MVC 4 - 02 Creating Layout, Views and Partial Views
Can't advice anything more specific as I don't really know what you WebForm application actually looks like but I think I described everything you need to start with.
Hope it helps!

Selected Index Change event of dropdwonlist in MVC4

I am very new to MVC and Presently I need to work on a Project in MVC4 with Razor engine.
So can any one tell me about
How to implement logic for SelectedIndex Change event of dropdwonlist in MVC4?
Thanks.
In MVC you can't do this. You'd need to use jQuery. OnSelectedIndexChange is a concept that is used in ASP.Net, and MVC3 is vastly different. If you want to implement logic when a user changes a DDL, you'd need a jQuery function to run when the DDL changes (onchange html attribute), which would then pass a request with AJAX to a controller on your page. Within this controller you'd be able to implement this logic.
I'd recommend getting familar with the concepts of MVC first. Practises in ASP.Net are rarely interchangeable with MVC.

Porting ASP.NET (Telerik) multi-column combobox to MVC.

I need to port the functionality of this one and only one AJAX control to MVC, but given the poor selection of MVC controls out there, I think I need to bring this legacy control into the MVC world...
I'd rather not taint my MVC project with ASP.NET controls, and welcome json/MVC alternatives you know of. (post them if you know of any)
Sample UI that I need in ASP.NET MVC
Back to porting
Although it's unfortunate that I am left to porting this control to MVC, it seems to be a widely accepted practice since Telerik has detailed instructions on how do this.
That makes me ask:
How common is it for a MVC website to use ASP.NET controls?
Again I'll mention I don't want to do this so I welcome MVC-specific alternatives. That being said, I'll proceed with trying to merge that control with my existing site. </End Disclaimer>
If you click on this hyperlink, and look at the source code at the bottom, can you tell me where I should put the following in MVC?
Code behind (My first instinct is to use a Controller but another SO question indicates I should create a create a ViewName.aspx.cs file)
How do I port the SQLDataSource to the new "Model" way of thinking. I know they are different in nature but I don't know how to present data to a ASP.NET control in a way that it will consume the information.
How do I handle the AJAX component? This control has an AJAX component using callbacks. Yes this is getting ugly, but it seems like I have to do this.
Apparently this model saves data in session or view-state. I have no idea if this even work in MVC. Guidance, an alternate control, or a life preserver is much appreciated.
I've already done research and have instructions from Telerik here and here that describes how to get started with placing a simple menu, but I need a little assistance with the more complex controls like this one.
Note: For all the commentary that has hit this question, please remember that I only want this one ASP.NET control functionality; I can't find a comparable control in MVC.
porting from asp.net webforms to MVC is a paradigm shift.
Directly porting does not work.
The Model is where you typically describe your data and do the data access
the View is for displaying the data
The controller plums the other two together
So SQLDataSource is your data access layer and would therefore go to your model
the problem with the thought pattern of SQLDataSource == Model then you get away from the point of decoupling your presentation from data access
You have to think of MVC development as a new build
I would pick a book or video series from your preferred source and learn starting with MVC3 (it has some differences that simplify build speed and reinforce the difference between webforms and mvc)
Hope this helps.
This article explains how to run web forms and mvc together
http://weblogs.asp.net/rajbk/archive/2010/05/11/running-asp-net-webforms-and-asp-net-mvc-side-by-side.aspx
This is by telerik and explains the limitiation of the grid and what is need to get it to run.
http://blogs.telerik.com/aspnetmvcteam/posts/08-11-06/asp_net_ajax_controls_in_asp_net_mvc.aspx
Add an IFrame in your MVC view that just shows the WebForms page (or just use that control on a single WebForms page).
There is nothing that says you can't have a site with both WebForms and MVC pages. You can route a single URL to a WebForm just for this control.
Why not just use the telerik MVC controls? They work quite well. Either get them via a NuGet package or visit this link http://www.telerik.com/products/aspnet-mvc.aspx
I would rather use ViewModel instead of code behind
You don't have to throw away SqlDataSource you can use result set and buld from it your model, problem may be column names in result set... tricky but can be done
Since there is no components in MVC except helpers youll need help of jQuery probably, it easy
$.ajax({
url : "/controller/action",
data: { /*json or serialized form */ },
successs: function(data){
//if you got response as html from /controller/action
$("#some_div").html(data);
}
}
Session is available in MVC but viewstate not, you can use HttpContenxt.Cache or TempData if you need something like viewstate. USe TempData to keep data between redirections, or httpcontext.cache to cache your data further more.
I can't find similar functionality in an MVC control
MVC doesn't really have a concept of controls in the same way that ASP.Net does - there are only really the plain old HTML controls (i.e. hidden input, text input, checkbox, radiobuttons, select box, text area, password and buttons).
When you need something more complicated than the plain HTML Controls you need to use some JavaScript to achieve this.
I'm not sure that you will be able to 'port' the control into MVC - you will most likely have to try and re-create it your self using an MVC controller and a partial view with a fair bit of a javascript to create the control.
Have a look at the JQuery UI Autosomplete plugin - you could probably use this to acheive something similar

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.

Migrate to asp.net mvc control implementing IDataSource

Given the situation:
A user control implementing IDataSource. It has a textbox or two, and a button. Now, when put on any page and adding a GridView with the DataSource being that control, presto you have a grid with filters .
How should I go about implementing this scenario in asp.net MVC ?
Any suggestions ?
Should I give more details ?
I think you've stumbled across one of the defining differences between ASP.NET MVC and WebForms. You can't do this sort of RAD drag-and-drop type stuff with MVC (right now). You'd need to basically build your own GridView View and stick in some filtering actions (with jQuery or something for clientside filtering). The user control could be made into a "partial view" in this case.
However, if this is the sort of application that you do often, I don't think that switching to MVC will give you many benefits (given the limited context information that you've supplied).
Your question is "How", but I think the more important question is "Why".

Resources