2 views, with 1 model

Vote:
 

I am Quite new to episerver, I have a solution that has an calender page. We have created a model and view (which holds a list of all the events) the view shows the events from this year. Now we would then need a archive page which would show everything else in the list. It would need to go on a sperate page.

How could i use the same model (events) but use a diffent view?

#176641
Mar 23, 2017 10:57
Vote:
 

Hi Lois I would suggest that the model in this case holds all the events needed to be displayed in the view. The view is just responsible for showing the calendar, bound to the events retrieved from the model.

I would probably create a Calendar page type with a property for setting the date range (maybe 2 properties a start and end date). This page type could then be used for the current events and archived events. Also if you had a requirement to only show events for the current month this would still work.

The Calendar page controller is then responsible for filtering the events by date range, binding this to the model and then presenting the view.

#176741
Edited, Mar 24, 2017 11:07
Vote:
 

I agree with Janaka's solution, if you have the same presentation for the two views (with the only difference being the dates represented in the view). This would be a more flexible solution since you can feed in different dates to get a list of events.

However, if the presentation/html is different for archived page or you need to have a different URL (for deep linking, SEO or other purposes) then:

  1. You can create 2 methods ActionResult Index() & ActionResult Archive() which returns a different view based on the URL.
  2. Use tags to have 2 separate views (which take in a view model with a list of event). You should be able to look at the Alloy implementation.
#176836
Mar 28, 2017 22:00
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.