Umbraco Model Builder Missing - umbraco

I worked on exists umbraco project, and in this project there is a model builder button that generate model and I can copy them to my visual studio and use them as model.
Now I started a new project, but In the new App I don't have the generate model button
This is my Previous Project
And this is my current project (without the generate model button)
How can I add models builder to my project, And How can I know which model builder uses on my previous project.

You have PureLive models configuration set up, which means exactly that your models are autogenerated and you don't need to fire it up via button. It may be helpful but also dangerous :)
The configuration is in you web.config file and you can change the mode of storing models there.
<add key="Umbraco.ModelsBuilder.Enable" value="true" />
<add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll" />
Check more info at Stephan's Wiki: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/UsingTheModelsBuilder and choose the best way to handle models inside your instance of Umbraco.

Related

Accessing a LocalDB within an ASP.NET website from another project in solution

I have an asp.net mvc 5 website using EF, LocalDB and Code First Migrations. Requirements have now dictated that I need a need to add a console application into the mix to do some scheduled work. However this console app must call into the database functionality exposed in the web application. Also of note is that we are using LocalDB for development, but will switch to a 'proper' remote DB for production.
As such I have created a new console application within the project and added a reference to the web application so that I can call its repository functions. I know this probably isn't the best way to handle things.
For whatever reason though, when calling Save Changes on the database context from within the console application, nothing is saved to the LocalDB database. The Save function returns a number indicating that a number of rows were inserted.
I get the feeling I am making a schoolboy error somewhere. What could it be?
i`v used this in the past:
<add name="DefaultConnection"
connectionString="Server=(localdb)\v11.0;Database=WebPortalDb" providerName="System.Data.SqlClient"/>
If you want to use the functionality/database from one Project to another project then use the following::
1) Include the 'ConsoleProjectName.dll' file into your 'MVC' project's reference
2) Use that Dll into the namespace of your file.
(eg. using System.Data.Entity)
in the same way you have to use the DLL into your namespace.
3) make an object of the 'console' application's class and use the methods & other properties defined in that class.
May be this much information will be helpful for you.
This we are doing for n-tired architecture, where there are different layers (i.e. projects) in a solution to be linked with each other.

MVC Sitecore project - how to add key value settings on web.config

Quiet new to Sitecore hence this basic question to start with...
I've got a MVC Sitecore project up and running. However, I would like to include some simple configuration values on AppSetting of web.config file. From what I read it's not good practice to mess with Sitecore config file.
Could any one please suggest the best practice to add key value on appsettings?
Should it go under app_config?
If yes, then which folder and what naming convention should I use?
And how does Sitecore reads this file on runtime?
In my current project I've removed all app settings from the web.config and included them like so:
<appSettings configSource=".\App_Config\AppSettings.config" />
I then use SlowCheetah (Which can be downloaded here) to change the settings in the AppSettings.config file if I have environment specific settings.
All changes to the sitecore section of the web.config I add through the include files. You can read more on include files in this post by John West

Add my own class file in ASP.NET MVC, and it couldn't be referenced?

I am currently stuck trying to add my own class file into ASP.NET MVC project, so it could
be referenced by my controller. But Visual studio 2010 always complain about "The type or name 'Products' could not be found (are your missing a using directive or assembly reference?)
I am not sure where to put my class file and tried add the class to Models or Controllers directory, and it wouldn't work either. My the class is under the right namespace, and I did reference the Models namespace in my Controller. It could be something obvious, but I couldn't get it working:(
Make sure that the "Build Action" property of the file is set to "Compile" in Visual Studio. Perhaps when you initially added the file, you added it to a location or added it as a file type that did not automatically set the build action properly.
The general rule of thumb is that business objects go it the Models folder you're correct. If it isn't working you don't have the project configured correctly. In the controller where you wanted to reference the Products object, did you add a reference to Models.Products?
Are there any other errors in listed? Sometimes multiple errors in a solution can combine to create something like this.
Ensure the namespace of your class is correct.
Based on a comment to a different answer, it appears you're trying to add a utility or helper class. I suggest you put it in a Helpers folder under the root of the project.
So first add the Helpers folder under the root of the project. You should have the following structure when done (there may be other folders as well):
[project]
- Content
- Helpers
- Controllers
- Views
Now, add a new class to the Helpers folder. Call this class ProductsHelper (in the Add New Item dialog make sure to put ProductsHelper.cs, as it's asking for the file name).
Now have a look in the new ProductsHelper.cs file. Copy the namespace found in said file, to be used in the controller.
Now, add a using directive at the top of your controller that looks like the following:
using [copied namespace];
Sometimes projects are set up to use default namespaces that don't match the project name, in which case the namespace in your newly-added class file might be different than what you thought you should add as the using directive. If you're wondering what the default namespace for your project is, you can see it in the project's properties, on the Application tab, in the "Default namespace" textbox (you can change it here as well).
I had the same problem adding some utility class .cs files to my new MVC project.
I was working mostly on VS 2010 Website projects which compile differently from
Web Application Projects ( WAP ) like the MVC 3 Project.
Just to clarify Jacob's answer, In the VS Solution Explorer: right click on the class .cs file and select the Property Dialog and then set the property: Build Action to Compile.
This will force the code to be compiled when you Build the project.
HTH, LA Guy

Visual Studio: How to override the default "Build Action" for certain extension types per project or solution?

I'm serving my asp.net mvc views from many assemblies and copying views to the main application on post-build event.
This works, however, I realized, that when I change something in view and just hit F5, changes are not included. What I have to do to see changes is to: save, build<- explicitly clicking, and then hit F5. However, it's pretty annoying solution.
I discovered that setting Build action to "Embedded Resource" on view solves the problem as well, however other devs may not remember that they have to do this after adding every view to the solution.
Is there a way to override the default build action for certain file extensions, such as: *.aspx, *.ascx in project or (better) in solution ?
What I've found is an ability to add this setting globally, per machine, but I do not want to do that (link: http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx)
Any ideas ?
Consider the following project file outline:
<Project ToolsVersion="3.5" DefaultTargets="EmbedViews;Build" ...>
...
<Target Name="EmbedViews">
<ItemGroup>
<EmbeddedResource Include="Views\*\*.aspx" />
<EmbeddedResource Include="Views\*\*.ascx" />
</ItemGroup>
</Target>
</Project>
This will add all aspx and ascx files in Views\<subfolder> to your library as Embedded Resource. Notice that EmbedViews is added to DefaultTargets before Build - order is important here, I found out making that mistake myself :-)
Since editing all your project files to get this snippet in is cumbersome, you could make your own project template with this included.
Please let me know if this helped.
In case anyone wonders here - there is still no way to do that if you want it to work on current and future items.
In VS 2017 when adding new file when the catch-all rule is present (e.g. Content Include = "**.*ts") if you add a new file, it will add it's own line to
<ItemGroup> with it's own BuildAction, ignoring your predefined catch-all.

Can WebForms and MVC live in a single project?

I'd rather be doing MVC as the regular WebForms development eats my soul.
However, I've been given a fairly sizable WebForms project to add a bunch of features to.
Is there anyway for WebForms and ASP.NET MVC to coexist in single project or even jointly handle the website? I know I am asking for a hack.
Here goes...
Make sure your project is targeting .NET 3.5
Add references (and make sure they copy to local) the big 3 assemblies for MVC (System.Web.Mvc, .Abstractions, .Routing)
Add a Global.asax if you don't already have one in your project.
Go to Global.asax code behind and add the necessary code to make it look just like an MVC Global.asax (I'm not going to type it out, just create a new MVC project and look at the Global.asax and add the things your current Global.asax code behind is lacking)
Create the top level folders for "Controllers" & "Views"
Create sub-folders of "Views" for your corresponding controllers (ex. Views -> Home)
When you add .aspx files to you view folders be sure to change the base class from System.Web.UI to System.Web.ViewPage and remove the tags
Start a new blank MVC project and do a find for "UrlRoutingModule" in the web.config and add those refrences to your WebForms web.config in the same places
Check the system.web -> pages -> namespaces node of the new MVC project and add the MVC specific ones to your WebForms web.config
This is a very rough explanation but you asked for the cliff notes. Moral of the story is to follow along with a new/blank mvc project and add the necessary entries in web.config, reference the necessary assemblies, and create the correct file structure for the mvc pattern.
I haven't done it - but it appears to be possible according to this Chad Myer's blog post. It's a bit old.
http://www.chadmyers.com/Blog/archive/2007/11/30/asp.net-webforms-and-mvc-in-the-same-project.aspx
This is what I did to add MVC5 to an existing Web Forms project
Create a new ASP.NET MVC project. You can use it to copy info to your existing project.
In your existing project, use nuget to add the references. This will also update your Web.config and add the jQuery files. Copy this in your Package Manager Console
Install-Package -Id "Microsoft.AspNet.Mvc" -Version 5.2.2" -ProjectName ExistingWebApp
Install-Package -Id "jQuery" -Version "1.10.2" -ProjectName ExistingWebApp
Install-Package -Id "jQuery.Validation" -Version "1.11.1" -ProjectName ExistingWebApp
Install-Package -Id "Microsoft.AspNet.Web.Optimization" -Version "1.1.3" -ProjectName ExistingWebApp
Install-Package -Id "Microsoft.jQuery.Unobtrusive.Validation" -Version "3.2.2" -ProjectName ExistingWebApp
Install-Package -Id "Modernizr" -Version "2.6.2" -ProjectName ExistingWebApp
Copy BundleConfig, Routeconfig, FilterConfig and any others you need to App_Start
Add the register lines from Application_Start to Global.asax. You can get them from your new project.
Add these keys to the <appsettings> of your Web.config
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
Add a reference to the Microsoft.CSharp assembly
Add the Views and Controllers folder
Now you can start adding views and controllers as you would do in any Mvc project
If you have room for another book I highly recommend Steve Sanderson's book http://bit.ly/1W03Tv (I'm not a mole...it's just helped me a ton). He has a chapter in there about "Combining MVC and WebForms".
I thought about summarizing the process out here but it's a bit lengthy. Give it a look if you get a chance.
Now in 2011 we have .NET 4.0 and is fairly easy to combine them. Just start a new MVC3 project, add a HomeController and a view (i.e. Home/Index.cshtml), then add a new folder, let's say /Admin, then add a web form inside it like /Admin/Default.aspx... that's it, run it, the home page will use MVC, the admin section will use web forms.
Also - in order to add the context menus, add the "MVC" project type ({E53F8FEA-EAE0-44A6-8774-FFD645390401}) to the project file as such
<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{...};{...}</ProjectTypeGuids>

Resources