Collection view and composite view in backbone.js - marionette

Can we use regions inside collection view and composite view in backbone.js?

The short answer is no. Only LayoutView has support for regions. If you tell me more about your usecase, preferably in the form a jsfiddle, I'd try to to give you code sample to address your usecase.

Related

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.

Using view model in Partial View defined in Layout

This is all hypothetical, and wondering how and if this is possible.
I have two different strongly-typed views that use two different models. For example, I have a View1.cshtml, and View2.cshtml. Each has it's own model: View1Model.cs and View2Model.cs. Each of the view pages uses a common layout (_Layout.cshtml) that has a PartialView (_WhoAmI.cshtml).
In the View1Model.cs there is a UserID field (with various other fields) and the View2Model.cs also contains the same UserID (with different fields than View1Model.cs).
The partial view will lookup the UserID and display the User's information in a small display .DIV.
What is the best way to do this and keep the PartialView strongly-typed? Is it even possible when both models of the view are so different (other than the UserID)? If so, if I use this PartialView again in the _Layout, how do I keep it from doing the User lookup two times in the Layout page for each time the partial is called?
Thanks in advance!
Instead of Html.Partial you could use Html.Action and have a child action rendering the partial and doing the necessary lookups.
I assume that if partial view has model of type dynamic then what you ask might be possible, but haven't tried it myself. At least MSDN says that dynamic variables are bypassing static type checking and at runtime they are only checked for existence of specific methods that were called from code.

Bind various panaroma/pivot items using MVVM

could someone help me with design/understanding the problem: what I need to achieve is page with Panorama/Pivot control, where its items (panos/pivots) will be set via binding, using standard MVVM pattern. Problem is I need to have different content (different user controls) on each pano/pivot, that means If I define a panorama/pivot item template, I doom all of them to be alike, which is not what I want.
I found this question here already asked: Databound windows phone panorama with MVVM design but its still not clear to me. Many thanks.
If you have a dynamic page count on panorama/pivot you could use selector to choose what template is right according to your content.
Implementing DataTemplateSelector
Also, Data Binding Pivot to MVVM may help you too
You could add a dependency property to the user control that you want to use as a data template, a dependency property named "Type" for example and depending on that property you can change the layout of your user control (data template) - for example you could have multiple grids inside your user control and you could show and hide them depending on the type.

Setting DataContext in UserControl from ViewModel

I have a View that contains a Listbox. I'll call it CityListingPage.xaml. This list page has a CityListingViewModel, that is binded with the View like somewhat like this:
DataContext="{Binding CityListing, Source={StaticResource Locator}}"
This works nicely. Now I what to change my page to a Pivot Control, where the Pivot Items, would be instances of CityListingViewModel, but obviously with different constructor data (ie. Country)
I extracted the ListBox into a UserControl. Now I'm struggling how to make this work so that for each list I get a new instance of the CityListingViewModel.
I tried creating in the ViewModelLocator a collection of CityListingViewModels but how do I pass the a CityListingViewModel instance to the UserControls DataContext?
Perhaps there is a different, better way of doing this?
Without seeing your code, I'm going to do a little guessing, but I think you can do it directly via data binding. Since each pivot item is getting an instance of CityListingViewModel, you can just pass that binding along to the UserControl:
If you post a little more code showing what you're trying to do, we might be able to be of more help.
The following are two answers for using a collection to create panorama pages. But I am quite sure that the approach can be adapted to pivot pages:
Dynamically add eventtocommand actions to a listbox
Static and dynamic panorama items in a panorama wp7 mvvm
The second post should be more relevant.
If you are thinking of partitioning the same data over multiple views on a pivot page then I would suggest NOT using several view models, especially if it is the same datasource you are using for all the data.
Simply have a parameter which each view would bind to and use Linq to control what data is visible to that parameter.
So you will have the variable which will contain all the data to be displayed and one parameter per view querying that data.

MVC3 - Conditional View Rendering

I have a conditional business logic that determines whether a property from a model should be displayed in a view. according to best practices where would be the place to implement it?
Implementing this logic in the view level does not seem right to me.
Thanks
IMO, it is belonged to the Model. I would put that business logic in IsRequiredYourProperyName property in the model.
Really? I would have thought that would be fine in the view provided you're passing the boolean indicating whether or not it should be displayed as part of the ViewModel. The view shouldn't be querying an outside resource to see if it should render certain UI elements, but if everything it needs to determine what to render is in the ViewModel, what's wrong with a simple if{} statement? Alternatively if a conditional display property is common you could create a custom DisplayTemplate or EditorTemplate and for it and implement the logic there.
So your ViewModel should wrap everything you want to send to the view. in your case it sounds like it should wrap your DomainModel and some sort of dictionary or KeyValuePair collection detailing if each property should be displayed or not as booleans. That's what I would do anyway.

Resources