How to create dynamic partial view in ASP.Net MVC footer section - asp.net-mvc-5

i am working on one application where i need to display last updated date and time of data from database to layout view footer section so that it will display on all the pages of application

You have two options
create a Base View Model and make your layout strongly typed for this all your model should be inherited from BaseVM and in every Action you will have to populate the properties of BaseVM along with the model related to the Action method.
Create an Action Filter, which will I recommend.
for details check this
https://www.sharpencode.com/article/MVC/filters-in-asp-net-mvc/actionfilter

Related

How to update Layout in PortletLayoutListener

The goal is to implement a Tab Portlet - portlet for displaying and managing tabs containing nested portlets (similar to Nested Portlets Portlet).
One of the requirements is to remove the nested portlet references from Layout on Tab Portlet removal.
I implemented PortletLayoutListener and indeed, method onRemoveFromLayout is called on Tab Portlet removal. The listener updates the layout. While debugging the listener, I can verify that the changes were written to Liferay database (to LAYOUT table).
The Layout instance is obtained through LayoutLocalServiceUtil.getLayout(plid) method.
The update is performed with LayoutLocalServiceUtil.updateLayout method.
The problem is that the listener is called from UpdateLayoutAction, which afterwards updates the Layout itsef and overwrites my changes (it reverts them).
The question is - is it possible to update Layout in PortletLayoutListener.onRemoveFromLayout method? If not, is there other option I could use?
Hi the PortletLayoutListeners are intended to be used in relation to the portlet. So if you want to react on a change on the page in your portlet.
If you want to change the portal, I would have a look at the model listeners. Create a hook with a Layout model listener and try to make you changes in the afterUpdate method. But be careful not to affect the performance.
You may even require both of the classes one to make an indication and the second one to make a change.

Passing properties to a custom control using xp:include

When using an Include Page to dynamically load a custom control onto an XPage, is there a way to pass custom property values to the custom control as part of the include?
Peter, the include page doesn't load a custom control but another XPage. Pages don't have properties. However... the page becomes part of the component tree, so you have access to its contained controls using getComponent("thecomponent").getParameterMap (Off my head, might be called slightly different)
Does that help?

Can you compute which custom control to use?

Think "computed subform", but in Xpages.
On one of my custom controls, depending on a certain value, I want to either present a custom control that renders a drop-down list using a combobox or renders an input box with a type-ahead.
This is on a custom control that renders a view, with all view configuration choices handled by a document rather than design, so several different views utilize the same custom control.
For example: I have a By Status view using the custom control that has status as the first column and we use a combobox to allow the user to select which Status value to filter by. Another view is sorted by Requisition number and I want to use a type-ahead instead of the combobox.
My preference is to use the same dynamic view custom control for both and have a formula that determines which of the two (comboBox or inputText) to use. How do I compute which custom control to load?
(Credit for the dynamic view control goes to Scott Good's folks over at Teamworks Solutions.)
During it's life cycle, an XPage exists in two places. First of all a representation of the XPage's relevant components is stored on the server. Then the page goes through a lifecycle, retrieving properties from documents, checking which components should be rendered, retrieving the data for any repeating control such as a View Panel etc., and passing the relevant HTML to the browser. The browser is the second place it exists.
So you can't compute a custom control as such. All you can do is set the loaded property, and loaded needs to be based on a non-dynamic calculation such as a viewScope variable, the current XPage name, a view name stored on the XPage etc. What you would have difficulty doing would be using a different custom control based on data on that row entry.
The other option is the Dynamic Content control or Switch control from the Extension Library. Both are similar to using the loaded property, in that you're putting both custom controls on the page and choosing which to display.
From what you're describing, the loaded property should cover what you need.
Some time back I saw this question on StackOverflow where the author had used Include Page control (xp:include) to include custom controls using pageName attribute based on formula.
<xp:include>
<xp:this.pageName><![CDATA[${javascript:sessionScope.ccPageName + ".xsp";}]]> </xp:this.pageName>
</xp:include>
Similar to the technique described by Paul Withers in his answer the attribute of pageName is also computed on page load.

Global sidebar with widget support

I would like to make a layout with a sidebar that can have widgets from different modules. Lets say there shall always be a login widget at the top if the user isn't logged in then it shall show user info. The getting started album guide could use it to display the latest albums and so on, i hope you understand how i want to use the sidebar.
Could it be done with a config file in autoload and a small code that read that config and calls the widgets on every page load?
There are several ways of page composition in Zend Framework 2:
1. Switching between Layouts
By default, ZF2 provides you with a single layout template layout.phtml.
In real-life applications, you will probably need to have several layouts
and switch the layout for certain controller/action. In each of your layouts, you will be able to show different widgets/sidebars.
2. Partial Views
A partial view is a .phtml view template file which can be rendered by another
view template. Partial views allow to compose your page of pieces and reuse pieces
of view rendering logic across different view templates. This is accomplished through the Partial view helper.
3. Placeholder View Helper
The Placeholder is another useful view helper allowing for capturing HTML
content and storing it for later use. Thus, analogous to the Partial
view helper, it allows to compose your page of several pieces.
4. Forward Controller Plugin
With the Forward controller plugin, you are able to call an action (for example, the action rendering some widget) from another module/controller from your controller and grab the output of that action. Then you are able to incorporate that output into your page.
5. Use View Models for Page Composition
When you write action methods for the controller classes, you use the ViewModel
class as a variable container for passing the variables from controller to view template,
and for overriding the default view template name. But, actually the ViewModel class is more than just a variable container plus view template name. In fact, it is closely related to the layout and page composition.
The third big capability of the view model class is that it allows for combining several
view models in a tree-like structure. Each view model in the tree has the associated
view template name and data variables that can be passed to the view template to control
the process of rendering.
This feature is internally used by Zend Framework 2 when "combining" the layout view template and the view template associated with the controller's action method. ZF2 internally creates the view model for the layout template and assigns it with layout/layout view template name. When your controller's action method returns the ViewModel object, this object is attached as a child to the layout view model.
So, you can attach your own view models to the default view model to render the page of pieces that you want.

Mixing Orchard CMS content with module

I am currently working on an Orchard module. This module contains an MVC application including the views. I would like to make the module as configurable as possible. One of the items that I would like the customer to configure is the way the MVC views from the module look. Part of it will be determined by the theme. But not everything. Consider the following scenario:
The module contains a view for placing an order. The view displays a form in ´normal view way´. That is field labels and input labels. But at the head of the form each customer must be able to define his own set of instructions to display. Or maybe the customer wants to put there a message for pointing the customer to some other actions.
In the most ideal way I would have a content page where the customer can put all kind of content and one specific block that is the result of the view of the module. Kind like a web part. I can´t find out if it is possible and how that is achieved.
Edit for clarification
Module creates a page like this:
TITLE
FORM
So both title and form are outputted by the module controller.
I have managed to create a layer with the condition that the url matches the page with my form.
I have added a HTML widget to this layer in the content zone with position 1 (tried 0 to).
However the pages looks like this:
TITLE
FORM
WIDGET
instead of
WIDGET
TITLE
FORM
Returning a ShapeResult from your controller action will ensure that your view is themed and benefits from widgets, which are your "kind like a web part" thingies in Orchard.

Resources