I am very new to Umbraco and did just my first fresh install. Anyway, I am pretty sure I am missing something.
I created a new document type, my MasterPage. Inside my MasterPage I created another node called About.
Both my MasterPage and my About have generic properties.
When I create a new item under Content and under my MasterPage for About, I can only see and set the properties from my MasterPage?
Why is that? I understand that my About node is inheriting from MasterPage and that makes perfectly sense to me, but why does my About node don't have the properties I defined only for About?
I tried to find the properties, so I tried this to see whether my defined properties exist at least: (They exist in the database though)
#Model.Content.HasProperty("myPropertyAlias")
But strangely, in none of my content sites this is known?
Thanks for reading this,
I hope somebody can help.
Best regards
Edit for clarification:
First, thank you for your response. My structrue looks like this:
Document Types:
Document Types
Document Types -> MasterPage
Document Types -> MasterPage -> AnotherDocumentType
Templates
Templates
Templates -> MasterPage
Templates -> MasterPage -> StartPage
Templates -> MasterPage -> AnotherDocumentTypeTemplate
Content
Content
Content -> StartPage
Content -> AnotherDocumentTypeContent
The MasterPage has in its Structure option "Allow at root" set to true and in Info by "Allowed templates" both the MasterPage and the AnotherDocumentType template checked.
Now I add to my MasterPage one Generic Property from type of Textstring named PageTitle.
This works as expected. I now can inside my Content Section create one node for the StartPage and the AnotherDocumentType.
Both have the PageTitle and I can set it. Works perfectly.
Now, when I define a Generic Property for AnotherDocumentType, I am not able to set it through the Content Section in AnotherDocumentType.
I hope it is now more clear.
Thanks for your help.
Related
We have input like the control type and the name (for eg : Control Type : Label, dropdowm, radio button , etc., and Control Name : lblID) On click of a Generate, I need a CShtml page which should be binded with all the controls. Is it possible to integrate T4 template with my solution. We are yet to start a new application.
Heard about T4 template but all the examples specified with scaffolding options. I don't have this. By generally i need to create cshtml under views of my project. Requesting suggestion.
suggest a way to proceed. Thanks in advance.
I've created a template (View) in Umbraco (MVC) and am trying to figure out how to bind to the document type content. Keeping it really simple:
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = null;
}
<h1>#Model.Title</h1>
My Umbraco document type has a Title field (alias is 'title') but if I try and run this I get build errors. I've found a whole load of documentation suggesting using a Library.NodeById() method but I believe that's for WebForms and not MVC. Can anyone offer some guidance?
You can get a property value in multiple ways with Model::
#Model.Content.GetPropertyValue("title")
#Model.Content.GetProperty("title").Value
And as a dynamic
#CurrentPage.Title
Did you remember to add your template to your document type?
You can also use the Field helper method:
#Umbraco.Field("myFieldName")
nice thing about this helper is that you can also specify alternative fields (if the first one was empty.
You can find this back in the documentation:
http://our.umbraco.org/documentation/reference/templating/Mvc/views#RenderingafieldwithUmbracoHelper
I have my Model defined externally in two projects - a Core project and an Interface project.
I am opening the Add View dialogue from my controller, and selecting Create a strongly typed view.
In the drop down list, I can select the concrete types like MyProject.Model.Core.OrderDetails, but the interface types like MyProject.Model.Interface.IOrderDetails aren't there.
I can type the interface class in manually and everything works, but then the View content menu that lets you select the Create, Delete, List, etc scaffolding is disabled.
Is there some problem with using interfaces in MVC? Or is it something else I'm missing?
Edit: Just to clarify, if I select the concrete object and the whatever scaffolding I want, I can then edit the Inherits tag in the view Page directive and everything works fine, so there's no missing references or anything. It's just the wizard doesn't seem to want to work with the interface.
Well, you could always select the concrete class implementing the interface, generate the partial view, and manually remove all the stuff that's not needed.
I have the requirement to support themeing of my site's pages. The way I am doing this is by dynamically choosing a master page based on the current theme.
I have setup a directory structure like so
/shared/masterpages/theme1/Master1.master
/shared/masterpages/theme1/Master2.master
/shared/masterpages/theme1/Master3.master
/shared/masterpages/theme2/Master1.master
/shared/masterpages/theme2/Master2.master
/shared/masterpages/theme2/Master3.master
And I am still using the page directive in the view
<%# Page Title="" Language="C#" MasterPageFile="~/Views/shared/masterpages/theme1/Master1.Master"%>
I would still like to leverage the view's MasterPageFile property and just change the theme directory.
I can only think of three ways to do this none of them which sound great.
Create a custom BaseView class that uses OnPreInit to change the theme like this
Create some xml file or database table that links each view to a master page file and then set this in the controller.
Build some tool that reads all the views and parses them for their masterpagefile, (similar to 2 but could be done at run time potentially.)
Option 1 seems the best option to me so far. Does anyone else have any thoughts on how to do this?
Updated suggestion:
Since my original suggestion didn't work out as I had expected, here's a possible way to work around it, while still keeping your action methods clean, and minimizing repetition of code:
Create an ActionResult that adds the master name/theme name/whatever info you need to pick the correct master page into ViewData["masterInfo"] (or something similar).
Create a base class which themeable views inherit. Your base class should, of course, inherit from System.Web.Mvc.ViewPage. If you need, also create a generic version that inherits from .ViewPage<T>.
In your base class, create a construction method that selects the correct master page based on ViewData["masterInfo"]. I'm not sure if there's a need or not, but don't forget to run the base constructor, either before or after your code, if there is one that needs to run.
Decorate all relevant actions with the attribute, and set their views to inherit your base class instead of System.Web.Mvc.ViewPage.
Original post:
Why not have an ActionFilter, that can be applied on controller level, that sets the MasterPageFile property of the view? If you override OnActionExecuted, it shouldn't be too tricky to test if the result was a ViewResult and in that case change the property to the correct value.
We are beginning the process of moving from Web Forms to MVC for all of our new applications. I am working on porting our Master Page over and am trying to satisfy the requirements that we need a single master page to be used by all applications. The primary navigation for the application needs to be in a menu within the master page. Accomplishing this was easy, the hard part is that each application may need to determine what to display in the menu using a unique set of rules. Some apps can simply say, here's the menu structure to use via something like a SiteMap. Others need to determine what is displayed in the menu based on what roles the user has, this can also be handled easily with a SiteMap. The situation that I'm struggling with is that some apps need to generate the menus based on the roles the user has, but also on the data on which they are working. i.e. The same user may have different option in the menu for a page if they are working on object 'foo' than they do if working on object 'bar'.
What I've done at this point, is I've created an HtmlHelper that is called by the master page view and takes a list of objects of a custom type and returns an unordered list that is styled by a jQuery plugin to display the menu. The list of objects the helper method takes are passed to the view using the ViewData dictionary. Currently, the value of this ViewData node is set within the constructor of each controller. This allows each page, and potentially each method, to set a different menu without having to set the value in each action method, unless its needed. I have also created a class that parses a SiteMap and returns the list of items needed to build the menu. This class is what I'm using to set the ViewData value in the controller. The idea being that if an application needed more control of how the menu data was generated, they could create their own class to generate the data as long as it returns a list of the correct type of objects.
This solution seems to work fine so far, it just doesn't 'feel' right for some reason. I'm hoping that I can either get some ideas of better way to do this or some reassurance that this is a valid approach to solving this problem.
If it is something that will be on every page, do something like this:
Create a base controller:
public class MyBaseController : Controller
Have this controller get the data it needs and send that data in the ViewData["menu"] to the View. Then have all your controllers inherit from this one:
public class HomeController : MyBaseController
In the Master Page, loop through your ViewData and create your menu.
(I did something like this for my sub-menu which displayed a list of categories.)
In the book I am reading (Pro ASP.NET MVC Framework by Apress) they use Html.RenderAction for the menu in the masterpage. I am a Asp.net MVC novice so maybe somebody else can give more info about this.
You can download the sourcecode at apress.com though so maybe that could help.