Dynamic scaffolding of multiple domain classes with single controller - grails-2.0

For my web application in grails I have 3 admin controlling domain classes and no need of special UIs. For this I have decided to use dynamic scaffolding.
static scaffold = true; is scaffolding only one domain class.
Is there any way to scaffold all these 3 domain classes with a single controller. ?

I have found the solution.
We can scaffold a domain class from another controller by mentioning the name of domain class needed to scaffold dynamically.
For example:
static scaffold = User;
This scaffolding is happening in run-time only. So if we need to avoid scaffolding and if we wish to add actions manually we can eliminate the above code of line.

Related

No Views folder is auto-generated when I create MVC controller with views, using Entity Framework in Asp.Net Core

In my Asp.Net Core application, I am adding a new controller such that its relevant View folder (Course) be auto-generated under the Views folder when I click on MVC controller with views, using Entity Framework in the Add Scaffold dialog box. Under the Add Controller dialog box, I've selected Course as my Model Class and SchoolContext as my Data Context Class. When I add the controller, No Views folder is created for the CoursesController (The default name for this generated controller). I am following this tutorial and everything works fine for the StudentsController I've created earlier.
Any help will highly be appreciated. Thanks in advance.
I've checked on the Generate Views checkbox in the Add Scaffold dialog box after choosing my Model Class as Course and Data Context Class as SchoolContext and it works.

Is it possible to use MVC without Asp.net pages?

I know that MVC is a design pattern that separates Model, View, Controller.
Model - Logic
View - Client View
Controller - connection between the two.
In case I want to change one of this things it will be easy just to change view\Model and the controller.
So is it possible to use only WebApi and MVC without Aps.Net pages (cshtml files)?
You can return html files
return new FilePathResult("path/FileName.html", "text/html");
And .cshtml files are Razor View Engine files, not Asp.Net pages.
You can alson change the view engine, see here for a list of .net view egines.
In short: yes, you can.
To elaborate: not sure what you mean, as .cshtml files are essentially the view part of MVC (the V part). ASP.NET MVC controllers by default return content of the .cshtml file by calling View() helper method.
But you can for example render html for the client inside your custom controller class without calling for a static html content. Or you might create WEB API project, with routing, models, and controllers, but no views - just plain data returned to the client.

Generating a CRUD Controller in a different bundle

I want to generate some CRUD controllers with the following command:
php app/console generate:doctrine:crud
my problem is that I made 2 bundles (1 front end and 1 for the admin section) my entities are in the defaultbundle, but I'd like to generate the CRUD controllers in my admin bundle, is there a way to do this?
Generating CRUD controllers in a bundle different of the entity's one is, as far as I know, impossible.
Indeed, CRUD controllers generator is just here for test. But if you really want to use it, you can actually copy the controller, views and form in the other bundle. You'll just need to change the templates' paths and the namespaces at the beginning of the controller and the Form type.

Can I have both a Controller and an ApiController for the same thing?

I've just started to use the VS 2012 RC, and I'm creating an ASP.NET MVC 4 web application in which I plan to provide both an HTML-based user interface and a WebApi-based programming interface.
For my HTML website, I have a controller and view for each of my models (MVC!), and the routing works "by convention" so that, for example, the URL /client hooks up to my ClientController. My ClientController derives from Controller.
For my API, I will create new controllers that derive from ApiController. I naturally want my API URLs to be similar to my HTML URLs, so I'd like the client info to be available at /api/client. However, with the by-convention routing, that would suggest that I need an ApiController named ClientController. And I already have a ClientController class.
How do I deal with this? Do I need custom routing? Do I put the API classes in different namespace so that I can give them the same name?
Update: this question seems to suggest that a different namespace for my API controllers is all I need: Mix web api controllers and site controllers
All it requires is for the controller classes to be in a different namespace, and all is well.
Using MVC areas would also work (as suggested in gordonml's comment), but this effectively puts the controllers in different namespaces, so it's a more formal way of achieving the same result.
You may take a look at the following blog post which illustrates how an Api controller could serve Razor views as well. Basically he uses the RazorEngine to parse the Razor view end serve it.
For anyone looking for step by step guidance on how to do this on WebApi project:
Create two folders / namespaces, namely: ControllersApi and ControllersWeb
Right click on ControllersWeb and go Add -> Controller and select MVC 5 Controller - Empty. This will add all other dependencies if you didn't have them in your WebApi project.
Your RouteConfig will now register those classes that inherit from Controller base class. You'll likely need to add link to default Controller, by editing defaults to say: defaults: new { action = "Index", controller = "Home", id = UrlParameter.Optional }
That's it, you can now run site and use both API and Web controllers.

MVC3 - add a folder to controllers?

I want to learn is it possible to add additional folder to Controller folder. My reason is pretty simple: I want to divide my project administration and client sides.
Example: I have a controller named Post that has actions Index, Details, Delete, Create, Edit. I want to make one controller as user controller that will consist of Index, Details and another controller as admin controller that will consist of Delte, Create, Edit. Then I will be able to easy distinguish what is what and put admin validation on whole admin class.
Another reason is that I want my url for administrating my site to look like /admin/post/delete, not /post/delete.
So is it possible, and if so then what would be the best way to implement this?
Sound like you want to use MVC Areas? http://www.c-sharpcorner.com/UploadFile/b19d5a/areas-in-Asp-Net-mvc3/
It's just a convention on placing controllers in Controllers folder.
Actually MVC finds controller in current loaded assemblies.
You can place them even in other assemblies.
So, fell free to create additional folders inside Controllers
If you are using Ruby on Rails, yes, you can. In your routes files, config/routes.rb, add this:
map.namespace :admin do |admin|
admin.resources :posts
end
Go to your terminal and navigate to your project, run rake routes. Now you get your posts controller under admin namespace... and your url will be:
.../admin/posts

Resources