Cakephp bake equivalent in asp.net mvc - asp.net-mvc

I was developing with cakephp for a few years and now want to try out asp.net mvc.
In cakephp there is a bake plugin, that allows to create standard functionalities based on customizable templates. E.g. changing these templates according to my needs
1) for controller
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Controller/controller.ctp
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/Controller/index.ctp
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/Controller/add.ctp
2) for model file
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Model/table.ctp
3) for view files
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Template/index.ctp
https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/form.ctp
I could run a command from CLI and get full functional validation, controller files with actions and view files - based on the existing tables' structures and relations between them. The plugin will create actual php files in corresponding directories with content according to template files. Having pre-customized bake templates allows to generate the CRUD or any other custom functionality in a few minutes.
Is there a similar functionality in asp.net mvc (v5 or above)? The desired features are to be able to fully customize the templates, which will be used to create controllers, cshtml files and model files - assuming that we already have the tables with foreign key associations in the database. (Preferably free, but not necessarily)
Thanks

I think this link might help you with templates in visual studio. If you want to use command line, maybe yeoman can help you. See this link to see if it'll work for you.

Related

ASP.NET MVC EditorTemplate sub folders

I am working on, what I would consider to be, a large ASP.NET MVC website. Currently there are nearly 100 editor templates (all for 1 controller), and this number will grow.
What I want to accomplish is organize my views to make them easier to find and version. This 'version' step is what will make the views multiply as time goes on. you can think of this project as an Question/Answer application, where Exams are created, and can be pulled up later. Basically, for this particular project, the views/EditorTemplates can't really change once in production, so a new copy must be created for future use. References to the old view would still exist, making that exam look and behave the way it did a year ago. Likewise, new exams will automatically pick up the new version of the view, and use that version.
I would like to have this type of structure, but I am up for other ideas.
Views/Shared/EditorTemplates/Common
Views/Shared/EditorTemplates/Common/v2
Views/Shared/EditorTemplates/Common/v3
Views/Shared/EditorTemplates/Department
Views/Shared/EditorTemplates/Department/v2
Note: Even though I will have versioned subdirectories, which implies that I will have multiple versions of the same model and template, the new files will have a unique file name. Also, I am also attempting to use the Razor Generator to compile my views. Not sure if that can be extended to add the additional EditorTemplate search paths or not.
The framework won't look there, use local EditorTemplate folders instead, e.g. Views/Department/EditorTemplates.
Editor templates are located by the view engine, which first looks in ~/Views/{1}/{0}.cshtml and then in ~/Views/Shared/{0}.cshtml.
For example, if the controller is Department and the model is a String, the framework asks for EditorTemplates/String, and the view engine looks in ~/Views/Department/EditorTemplates/String.cshtml and ~/Views/Shared/EditorTemplates/String.cshtml.
Max's answer is a much more elegant and simple answer. If you don't want to do that AND you want a ton of work, you can write your own ViewEngine.

mvc webpage without using the default templates

I am using MVC 4.I have designed a webpage in Dreamweaver and then tried to convert it as a razor page. I wanted to view it in a browser, without using Visual Studio. I have heard that a Razor page can be edited using a notepad.
Please help, I am comfortable designing pages in Dreamweaver, than in Visual Studio.
If I understand you correctly you have a HTML design (created in whichever tool you prefer) and you wish to create an MVC website out of this. You have experience in ASP.NET Webforms.
Primarily to creating anything I would follow the topics covered in the ASP.NET MVC tutorials of MVC itself. It's not about "default templates" it's about understanding what builds your final output. Layouts, partial renderings etc...
See http://www.asp.net/mvc
PS: Ask yourself: Is MVC the right choice for my solution? (because I get the feeling everyone just wants to use MVC and doesn't think about what it is and why you should or shouldn't use it...)
If you dont't want to use default template then you can include your css files you created in Content folder. In shared folder which is located inside Views folder you can create the your customized layout which uses the css that you included in Content folder. And you can then include these layout in the views you later create inside shared folder of Views.
You can explore yourself by installing twitter.bootstrap.mvc4.sample from package manager console and see how your project changes.
This package changes your default layout to different layout, which is pretty cool.
Hope you can get idea of what is done and how you include your own layout from this above mentioned package.

following iterative and agile in asp.net MVC

ok, i know there are a lot of posts online that specify how to do iterations with MVC.
my question is slightly different. when i used to do iterations using WebForms, i was creating one thing only and finishing that one thing till the end which was including the deployment on production.
for example, i was creating a webpage and deploying it, then i create the second page and deploy it. so .dll files were added to my bin folder while the previous dlls remain untouched. at the other hand, when i was making a change latter on, there was this one file that needed to be replaced on production.
now here is the question, how can i acheive the same thing in mvc? beause it just doesn't deploy each page into an individual dll. each time that i add something i have to redeploy the application dll which is not really wise! i played around with deployment options in visual studio but no luck!
There is nothing preventing you from putting controllers and other code in separate assemblies and dropping them in an existing application. Like any ASP.NET based application an MVC application will automatically restart if you add or modify any file in the bin folder or modify web.config.
If you're using Razor you can use RazorGenerator to generate code for your views and compile them into the same assembly.
You may need to write some additional logic though to get routes, model binders etc. wired up correctly.
For a more structures approach to compose the application of separate modules, you may want to look into portable areas. This is an extension to ASP.NET MVC that allows you to package the entire module (including views, css, js etc.) into a single assembly.
First thing, you have to work on the title of the post, it does not match the content of the post.
In asp.net mvc u can choose to deploy only what changed. I.e. If you only changed the .cshtml file, then you can just replace it with the file in production. However if you change any controller class (C#/Vb code), then you will have to upload the web project dll file too so that this new changes are available in the production env

What are the steps for converting the view engine for an MVC project from .ASPX to Razor?

I've inherited an MVC3 project that has a large number of ASPX views that I would like to convert to Razor. This question => Aspx to Razor syntax converter? is similar to mine, and it helped me find a bunch of options for converting the views themselves, but I'm unclear on the steps I need to take in addition to converting the views.
The first known limitation of Telerik's razor-converter is "The tool only works with views and does not deal with the project structure and master pages". This tool claims to be able to convert master pages as well, but it doesn't look like anybody beyond the developer has ever used it.
I think these are the steps I need to take:
Use a utility to convert the views
Convert the master pages manually (how do I do this?)
Modify the project structure (what needs to be modified?)
Delete the ASPX files
Test the application (any specific gotchas I should look out for?)
Are these the right steps? Can you help me with my questions on steps 2 and 3?
I have only tried this on one solution and the actual conversion did a fairly good job. I downloaded the Telerik converter project, compiled it, and then converted my projects using these command lines:
aspx2razor C:\Development\MyProject\MyWebProject\*.ascx C:\Development\MyProject\MyWebProject -r
aspx2razor C:\Development\MyProject\MyWebProject\*.aspx C:\Development\MyProject\MyWebProject -r
aspx2razor C:\Development\MyProject\MyWebProject\*.master C:\Development\MyProject\MyWebProject -r
I only needed to go back to add an #include for a namespace here and there, and to add a few parenthesis to force the Razor view engine to recognize my inline code properly. This was also a fairly simple solution, so YMMV. But even if it converted 80-90% of your views successfully, it's that much less manual work which you would have to perform yourself. From here, you could also create a _ViewStart.cshtml file and make a few minor adjustments to take advantage of Razor-specific layout features. (Check out Scott Gu's post on it here: http://weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx)
The big issue I had was trying to reconcile the file changes with source control. Since the classic MVC view engine uses .aspx, .ascx, and .master extensions, I had to manually add the .cshtml files to my MVC web project and source control then remove the old versions. It wasn't difficult, just time-consuming.
In addition, you may need to add all of the necessary web.config entries to support the Razor view engine as well if your project was created using MVC 1 or 2. Projects created with MVC 3 should already have these entries in place, even if it was not originally created as a Razor site.

ASP.NET MVC3 - Distributing EditorTemplate in library project?

Is it possible to distribute an EditorTemplate control ASCX along with a type in a library project and have it be used by MVC3 when the type is rendered with the EditorFor() method?
Where I work we have a lot of DateTime, Gender and a few more custom fields which have a specific but concsistent way of (HTML) input and a corresponding backing ViewModel type for them (i.e. DateTimeViewModel with separate month, day, year field etc.) and they are in a shared library project.
However we still have to copy the EditorTemplates for these types to each project which is not very DRY.
So is there a way to bundle such EditorTemplate along with the library project and make sure that it's used when the corresponding ViewModel is used without having to copy all EditorTemplate to every projects?
You need a custom VirtualPathProvider to achieve this but nothing out of the box. Here's a blog post you may take a look at.
Disclaimer: Custom VirtualPathProviders don't work with precompiled web applications. So if you intend to precompile your web application before shipping don't use virtual path providers.
Because of this limitation personally I use custom NuGet packages that allow the developers to pull all the necessary templates to their corresponding locations.
You could create your own VS Template, Export it and distribute it to all of your developers I think.
Write Templates for VS2010
You can register your own VirutalPathProvider implementation:
HostingEnvironment.RegisterVirtualPathProvider(new YourViewProvider());
Then you will be able to get your files from basically anywhere (for example from embedded resource).
Hope this helps.
I think this is not currently possible. ASP.NET MVC editor templates should be defined in a partial view file. There is no way to define them in code only.

Resources