Views page and AJAX - drupal

I created a page view where it lists all nodes grouped by content types. My problem is how to create a page which will only output the view, I mean without the headers, sidebars etc.. just the view content? My reason for doing this is I would later call the view / view page in an AJAX request and display to the user.
My view name is 'node_list', and I used the files views-view-list--node-list.tpl.php and views-view-fields--node-list--page.tpl.php to theme the output. But I have no idea how to create a page with only the view visible..
I hope you can help me. Thanks!

The easiest thing, is to create the call back for the ajax function and just return the view you want to insert using views_embed_view

Related

Many forms for editing entity on one page

I have a list of objects on my page. I need to edit an object in a popup.
There are many objects, and generating many forms for each object is not correct.
What can I do, can an iframe do in a popup?
You don't need to use iframe.
Build your form in your controller and render it in the html. The fact that it's in popup doesn't change anything. It doesn't matter if it's in popup or not, the final result will be POST call to your action.
You should have an action that renders a form, callable from an ajax in the view where you have all those entities.
Just change the entity id that will be received in the action as argument by changing the ajax url using js depending on the clicked entity you want to edit.
Then return with the ajax the form already rendered so with only one form you can edit as many entities (of the same class) as you want, without even need to render one form before they click which one they want to edit.

ASP.NET: Creating multiple printable pages and print them with one click

I want to achieve the following: create a number of instances of the same web page, each of the the pages displaying slighty different data (like customer name, address, ...). These pages should be printable with as less effort for the user as possible. The problem is that if you call the javascript print-directive on every page, the user would get a ton of the PrintDialogs.
One solution to solve this problem would be to create those print pages dynamically during runtime and put them all on one page, separated by page breaks (so the user would only have to confirm the print dialog once). This solution has the huge problem that I can't use the Visual Studio designer to put my page together.
Another possible solution would be to build the template of the page in the designer, dynamically fill in the customer-specific data into the corresponding controls for every page, and then somehow chain all the resulting pages together to one long page; again separated by page breaks. But I dont really know how to do that....I tried to use the Render() event, get the HTMl code and then duplicate it, but I didnt have much success with it.
So, any guidance for the Render() approach or any other solutions would be very welcome!
Is your data in any form of list? Can it be put into one? Not necessarily all of it, but an ID per desired page, or something similar? Sufficiently that it could drive a data-bound control?
You could use a Repeater control on your page to build out your "pages" according to a template. Page breaks could be achieved with CSS styles. Then you'd have just one (long) page you had to print.
You could even make your "page" a UserControl to make data-driven variations in rendering easier to organize.

ASP.Net Load Data from another page

i am facing one problem..
I have a page which has some templates related to user..
User use this template to send email..
User can have option to save this template and then he can load the saved templates...
What i want is on click on "Load Template" link. a new page appears which will display all the saved templates for logged in user. this page can contain grid. on select i want to close this load template page. and pass the text data back to previous page. which will display this template into text field. so that user can use saved templates.
How to do this using Asp.Net
You can do this using JavaScript, assuming the template selection window is opened with a call to window.open(). When the template is selected you can communicate and invoke methods (such as passing back the selected template ID) with code similar to this:
window.opener.templateSelected(selectedTemplateID);
window.close();
Here is information about window.opener
I believe that this may be what you're looking for. It's pretty straight forward and is in C#. It is done in .Net as opposed to client side JS.

posting an action from a partial view within a jquery dialog

I have an index page with a jquery tab loaded. Within one of the tabs I open a partial view company.ascx. Within that I have 2 RenderActions' One loads the company header and the other loads the branch information.
<% Html.RenderAction("Compheader", "Home"); %>
<br />
<br />
<% Html.RenderAction("BranchList", "Branch", new { Id = Request.QueryString[0], pdate = Request.QueryString[1] }); %>
Within BranchList I display a table of branches each of which has a delete button associated to it. There is also an add button on the branch list. Both these buttons open a jquery dialog that open partial views (acsx) within it. The dialogs have a submit post within them.
When the user clicks on submit on the insert/add or delete view I want to be able to refresh the BranchList action, which will get the new branchlist and display it.
Right now on post within the delete or insert I response redirect to the index page which refreshes the whole page. Can somebody tell me how I can accomplish this using Html.BeginForm and ajax posts in a clean way instead of the response redirect.
You are accessing QueryString directly within your view and that means that you are not using any of the goodness of ASP.NET MVC framework. You should get these values in action method (using the matching parameter names as the QueryString variables in the action method's constructor) and then pass these values from action method to the view (using a view model or ViewData) so that you don't have to access QueryString directly inside the view.
Now coming to your question, I think you are doing it right. If you are getting the right behavior from your application, then you should not change the post-redirect behavior of the application.
You are posting the data from the partial views and then doing a redirect. This is a valid pattern, also known as GPG (Get, Post, Get) pattern. This is advantageous compared to simply sending the user to their "Posted" page as it avoids from letting the user post the same data twice in case they refresh the page.
Hope it helps.

Paging search results with asp.net MVC

I have a situation that I couldn't find a solution for through my searches on here. Here is the scenario:
I have a search form with 2 required fields and multiple optional ones. The form posts to an action method that determines which fields are selected and builds a List<> of objects that match the search criteria. I then pass that List<> to the view for display.
This issue I am running into involves how paging is typically done with asp.net mvc. For past projects I have used a custom Html helper that creates links which include the query parameters as well as a "page" parameter. It then uses a GET request and the .Take().Skip() format.
I've hit a wall on this project as I can't use a GET request for the search criteria and I can't figure out a way to keep the List<> in memory to do the usual "page" parameter trick.
I thought about storing the List<> in the session but the objects and the list could be very large.
I would think this is a popular issue with advanced search forms but I can't seem to find a good solution. Any help would be appreciated. Thanks!
How about cacheing the search result object and giving it a unique key. You would then have your paging links reference that unique (SearchID) and have your action look for that object, pull it from cache and Skip/Take from there.
This will not rebuild the object for every request, making page loading much faster and reducing strain on your database/application.
Here is a article about cacheing:
https://web.archive.org/web/20211020111559/https://aspnet.4guysfromrolla.com/articles/100902-1.aspx
Here is a video about cacheing:
http://www.asp.net/learn/Videos/video-6206.aspx
Note: Be sure you specify expiration date on the cached object.
If I understand properly, you only want to load the search results one time, and then page through them.
Have you looked into any jQuery paging functionality? You can just dump the entire list to the page and use JavaScript to handle the paging (and sorting if you like).
An example can be found at http://beckelman.net/demos/jqueryTableSorterConPaging/default.aspx
Put everything in the same form: the required fields, the optional fields, the page links.
Two possibilities:
Use submit buttons or images instead of anchor tags for the page links each having a different name (e.g. page1, page2, ...): this will allow you to get the desired page when the form is submitted.
Put a hidden field inside your form. Then add a javascript click handler to any of the page anchors. This handler will update the value of the hidden field with the page, submit the form and cancel the event.
So clicking on any of the pager links will submit the form with all the data you need to build the list and pager links.

Resources