Many forms for editing entity on one page - symfony

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.

Related

Refreshing caller listpage form

I need to call parent form but my parent form is a listpage form.
As I know I can't add new methods to list page forms i need to add this method to the interaction class of related list page form. But I do not have an idea how to do it.
Would you have any suggestion for me?
You have two options:
Set the AutoRefreshData on the menu item on the list page. This will refresh the list page, I am not sure when (maybe it works best on action menu items).
Call element.args().record().datasource().research(true); from the child form.
You can refresh a datasource of a calling record.
You need to cast element.args().record().datasource() to FormDatasource so you can call research() or executeQuery() depending of you needs.
Also you can/must check if record is from a form by using method on common isFormDatasource(). If this is true than this record is from form.
If you need to refresh parent from another form you should do it in closeOk() method of this form or at the end of you logic in a class.

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.

MVC2 - How put common LOGIC control (Like Search/Find) on each page?

I'm having trouble figuring out how to do the following:
On every page (or every page I so desire), I'd like to put a common control widget (e.g. think - Search functionality that contains a textbox+button). What's the best way to do this, and who handles the submit button (assuming it is a submit button)?
i.e. what does my ViewUserControl look like? Does it have a form? does it use jQuery onclick""? Does it post to the main View's action method, or can I redirect it to another Controller/Action?
I have tried using RenderAction of a "Search.ascx" which contains a Form, and is handled by my SearchController... but in the SearchController, it then tries to call RedirectToAction... and I get a complaint about RedirectActions not allowed on Child Actions.
I'm a bit lost on what to do next, so suggestions greatly welcome!
Ray
You seem to be on the right track (using ViewUserControl and RenderPartial). But with the information you have provided, it is not easy to see what you other problems are (RenderAction , ...)
It is easy:
Create a UserControl (.ascx) and get a form in there with URL being /search/..., something that you can get back.
In your views, call RenderPartial and provided the view name
Create your controller to receive the post from your search. This is not the same controller as your parent view controller.
The best way to have the HTML elements show up is to put them in a master page, or in a partial that is referenced by your master page. I would have it be it's own form and submit to your SearchController.
Let me know if you want more particulars.
RenderPartial is the way to go here. Your control.ascx will consist of it's form and submit button.
What's the best way to do this
Probably a partial view. An .ascx file.
and who handles the submit button
(assuming it is a submit button)?
The partial view
what does my ViewUserControl look
like? Does it have a form?
Yes, it has a form. It should be as self contained as possible.
does it use jQuery onclick""? Does it
post to the main View's action method,
or can I redirect it to another
Controller/Action?
Well, whatever fits your exact scenario best. It should probably post to whichever action is most appropriate. That is not likely to be the main view's action, since the partial is reused in different parent views.
I have tried using RenderAction of a
"Search.ascx" which contains a Form,
and is handled by my
SearchController... but in the
SearchController, it then tries to
call RedirectToAction... and I get a
complaint about RedirectActions not
allowed on Child Actions.
You'll probably want to render it using RenderPartial in the parent view:
<%: Html.RenderPartial("MyPartialView.ascx") %>
Ok, I figured out what my problem was. The replies above are correct. I have my own Search.ascx user control and SearchController, I also used RenderPartial, but what stumped me was that I forgot to explicitly specify the controller/action... so then I was fiddling around with onclick events and Url.Action on my button instead.
<% using (Html.BeginForm("MySearchAction", "MySearchController")) { %>
Thanks to all who replied.

Views page and AJAX

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

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