Render several views that belongs to different modules in one region - marionette

I need to render two views in region App.mainRegion.
The first view belongs to the Module A, the second to module B.
What is the best approach for this ?
Some module C, should render layout.
Then Module C using request/response receive view1 and view2 and append views to layout?
Thanks!

One of Marionette's strong suits is deeply nested views which is probably what you're getting at here. I think the best approach is to pass a Marionette Layout to app.mainRegion.show() which contains two regions which would then show View A and View B respectively.
A quick note on .show() is that you only want to call it in the .onShow() method (rather than initialize() or onRender() or else you'll set yourself up for accessing DOM element sadness later (see my post on this)

Related

How to add to an ObservableCollection from a different view?

(I'm using Prism Dryloc) My application consists of two views. The first contains a single list view displaying strings and the second - an entry and a button.
The listview is bound to an observable collection in the first page's View Model. How can I add to the observable collection from a different view?
Great question! You're essentially trying to pass data between views, and there's several ways of passing data between Views in Xamarin.Forms.
The two ways that seem relevant for your case:
Either making the ObservableCollection a public static object (so there's only one global instance of it). Not recommended.
The better way is to use the messaging center so that the second page publishes an event when the button is pressed, that the first page is subscribed to. And it passes that information that gets added to the list.
If these don't work, elaborate your use case and I'll suggest some more

Laravel multiple model bound forms in a parent view

The overall concept that I'm attempting to do is create admin panel that has multiple "forms" on a single blade view. Each "form" is a blade.php file that has a form that is model bound to provide quick access to the model data on load. For example, let's say that I'm running a manufacturing line and there are three models (subviews) that I want to #include() on manufacturing.blade.php.
Parent view (manufacturing.blade.php)
Subview - Start time (start-time.blade.php)
Subview - Throughput (throughput.blade.php)
Subview - Supervisor (supervisor.blade.php)
Each subview has a submit button on it that POSTS to the assigned resource controller. My problem is how do I successfully load manufacturing.blade.php and include form model binding when I never call the index controller on the subviews.
Is what I'm asking even possible?
For what it's worth I figured it out right after I posted the question. The variables required for the model binding inside the subviews were the problem. I was receiving errors about the variables not available, blah.... when I loaded the parent view page. Obviously the variables aren't available when I call the subviews because they were never pulled in from the parent view. In other words I'm trying to access something that isn't there.
Solution:
In the parent view loading controller, perform all the necessary db call to obtain/generate the objects required for the subviews. After the objects are obtained use
View::share('startTime', $startTime);
View::share('throughput', $throughput);
View::share('supervisor', $supervisor);
That method (view::share) allows that variable, 'startTime', etc..., to be shared across all the blade views that reside inside of parent. Just be sure you add the lines right before you return the intended parent view from your controller.

MVC 3 Combinging multiple controls in one sort control template

I'm working on some forms, and often I can reuse the same amount and combination of fields together, is it possible to group them all as a template and then call it from the page?
For example:
2 radio buttons with labels and 2 texboxes under.
How is it called so i can do a proper research?
You can use Partial View, its like a reusable component.
These links will elaborate more:
http://www.devcurry.com/2012/04/partial-views-in-aspnet-mvc-3.html
http://www.dotnet-tricks.com/Tutorial/mvc/2IKW160912-Partial-View-in-Asp.net-MVC3-Razor.html
MVC3 Partial Views
Create a Partial View and keep your markup which you want to reuse in that. You can use these Partial views in other views as needed then.
You can use the Html.Partial helper method to call the partial views in other views.
#Html.Partial("RecentItems")
You can also pass some model to your partial view as well
#Html.Partial("RecentItems", Model.RecentItems)
Assuming Your partial view is strongly typed to a class which is of the same type as the type of Model.RecentItems, of the caller view.

Mvc base viewmodel render data within layout

I have created a base viewmodel that all of my view models inherit from. That part is easy.
All views are bound to a viewmodel (all are inherited from the base view model)
Within the OnActionExecuted method I insert a true/false value onto a property within the baseviewmodel depending on some conditions.
From the view side of things. I have a single layout page that some how I want to be able to read the property's value and render a different partial view based on the value.
Is this possible? I dont want to have to add the code to each of the views but I don't think I should be binding the layout to my baseviewmodel either.
If I can stay away from inserting the value into the valuebag that would be great as I need to be able to access these values anywhere in the application via strongly typed names.
what you want probably isnt possible because as you call a view from the controller then first the code inside that view is executed and then the layouts code is executed
to achieve what you are doing you can do 2 things
1. make the logic inside the controller itself and then render the correct view
2.call the layout from the controller giving it the name of the partial view in some property of the model or in the viewbag
Not sure I quite follow the use case, but rather than trying to render out a partial view, have you thought about nesting your layout pages.
I think you should be able to override the layout in the onactionexecuted, so you can set the layout dependant on the bool and that layout will render only the correct option.
Look here for an example:
Nested layout pages with Razor
HTH
Si

MVC3 global predicate filter

I am building an admin console and all controllers depend on a dropdown selection for customer.
I would like to move this customer selection to the layout and persist it across all controllers so that you do not need to select it everywhere.
What is the best way to go about doing this?
Thanks in advance.
Move the dropdown to your _layout.cshtml.
Create a BaseView that all views will inherit from and give it a property to store the Customers & Current Customer.
Create a BaseController method that will fill in a BaseView instance.
Store the currently selected customer on your session.
Create a Global Filter and have it check all views to see if they inherit BaseView. If they do it can convert them to a BaseView and then fill in the properties.
Write some code in the _layout that can use the View to fill in the dropdown. I'm a bit fuzzy here since my coworker actually did this part when we did something similar.
When the user changes the dropdown value you can use JSON to call an action method that will update the current customer in session.
I would consider writing HTML helper. You assume that all the birds can fly, but say one day you have another exceptional scenario and you no longer need this dropdown box. Alternatively include it in a partial view and render that view where you need it - it's only one extra line of code.
E.g.
#section main_content{
#{ Html.RenderPartial("MyPartialViewContainingDropDownBox"); }
}

Resources