I am in the process of developing an ASP.NET MVC4 application where one of the requirement is to allow the administrator of the application to add additional data capture fields in the screens. What would be the best approach to address this?
There are different approaches.
First we have to note, that the Model itsself should be strongly typed. That leaves you with the option to put your dynamic data into the Viewbag. Therefor you should put your second model, or dynamic model, which is not type of your first trongly typed model, into the ViewBag in your Controller action.
The second option is putting your additional datafields, which the administrator can add to the view or hide in the view into your strongly typed ViewModel, and just let the administrator tinker with the visibility of the fields.
In addition to that, you could generate two views for 1 action, one which the basic datafields and one with the full set.
Kind regards
Related
Having recently migrated from years of web forms, I’ve built numerous dot net core razor page apps - So I’m not a complete beginner but I am struggling to understand the best way to approach one particular scenario. I have a page that captures some header information but also needs to capture some additional data that is specific to the “type” of record being edited. In webforms I dynamically loaded a user control for the relevant type using a path name (the path name of the user control being linked to the type so the system knew what form to load). With user controls I could then handle the form submission which meant the logic could be completely different for each type/form. Whereas I can use view components to create the relevant UI in the same way in my razor pages app, I can’t then handle the post back from there. So what would be the best way to approach this in razor pages? To make matters more complex, the type (and thus the objet i want to capture) could be defined in a RCL (another project). Also the type needs to be defined in a database entry, so I need to be able to load it from a string. Whereas a standalone page for each type would be easy, the management of this data is on one place in the core system so I can’t have a different page for each one.
I am trying to create some dynamic forms using Piranha CMS. As far as I managed to learn it is not supported right now, so I'm looking for work arounds or alternatives.
What I want to do now is use the editor from the manager for other users. To be more precise: this is how the editor looks like inside my manager when I want to edit a page
I have a text input and a select, both are Fields and there are many more fields to be used.
I want the sys admin to create a page with a list of inputs like this, which right now are usable only by the admin. BUT make this list of inputs available for edit to other users as well. Is it possible?
I'm not sure how to extract this editor or behavior or even if it is possible. The problem is we really need the admin to be able to configure different form inputs for users as it is the main core of our functionality.
Any help/advice is highly appreciated, thank you!
The components in the management UI is not designed to be reused in the front-end application in any way. The edit models in the manager contains a lot of extra meta data since the UI is completely generic. If you want to build an edit UI in your front end application, and you're using MVC or Razor Pages, the simplest way is to.
Get the generic model instead of your strongly typed model, for example api.Pages.GetById(...) instead of api.Pages.GetById<T>(...).
Loop the available fields in your selected region (a region is an ExpandObject which can be casted to an IDictionary<string, object>).
Use the built in support in Razor by calling #Html.EditorFor(...) for the fields.
Using this approach you can easily create your own EditorTemplates for the different types of fields you use that will match the rendering in your client application.
Best regards
Håkan
Thank you for answering my previous questions and I appreciate the effort put in by you in developing Moqui.
In the field tag there is an attribute of validate-parameter so could please elaborate the use of it and how to use that attribute. Thanks in advance :-)
To be specific, it sounds like you are looking at the XML Form field element (form-list.field, form-single.field).
A form field can be validated based on the validation settings in a service parameter (there are many validation options there) or an entity field (just a couple validation options there). This is done automatically when a form submits to a transition that has a single service-call element (i.e. not an actions element), and these attributes are populated automatically. You can also specify manually which service/parameter or entity/field to use for validation.
This is all part of the support in the framework to do client side validation with JavaScript using server-side validation settings. Note that the validations are also done on the server, but you don't have to define/implement them twice.
when should I create new view in the same view controller and when should I create new view controller?
This is a generic question, without knowing what you are trying to do is difficult to tell you how to create an application. By the way, a little (and simple) explanation can be this.
Controllers must implement the logic of your application, they must "control" a particular feature of your application.
Views must show what the controllers want to show to the user.
So, if you want to create something with some kind of logic (user check / data loading and more) you have to create a controller, if you want to show to the user something you can create a view.
The difference between 1 or 2 controllers depends on you application, you have to create one single kind of logic use 1, otherwise if you have a big application with different feature then create N controllers.
The following is more of a guideline than a rule.
You need to create a new view controller when you want to modularize your code according to some parameters (I do it based on functionality). eg. DashboardViewController, SettingsViewController etc.
Inside a DashboardViewController we can have many things going on. Each of which might need a view to represent.
I think this is more subjective than objective. In one project I have, a new controller needs to be created anytime I need to change the tabbed navigation, or I'd end up with a mess of if/else in my onInit method that defines the tabs.
In other cases, it might be as simple as just asking yourself if it's a logical grouping. E.g. I have a UserController that manages adding/editing/removing users. Should I use that controller for login/logout/forgotPassword, or should I create an AuthController? Personally, I would separate it to an AuthController since the security for a UserController should be admins only while the AuthController lets anyone try to login. Then, when the user is logged in, do you do UserController for their profile or create a ProfileController since again there are permission differences. Any logged in user can manage their own profile, but that doesn't mean they should get access to my UserController.
However, you could put add/edit/delete/profile/login/logout/forgotPassword views into a single controller and just handle permissions on a per-view basis, and that wouldn't be "wrong". As long as you are keeping your business logic in your model and out of the controller, and keeping as much logic as possible out of your view...then you're already ahead of the curve and refactoring when you need to shouldn't be too hard.
If you find yourself doing a lot of if/else in your onInit where you are initializing based on which methods are being loaded...that would be a sign to me that you should probably look at creating a separate controller.
I am currently investigating the possibilities of different CMSs for a company-site.
Done quite a few projects in classical ASP, ASP.NET, Joomla etc..
I would like to use Umbraco 5 for the first time.
For that project we have a SQL-Table with Job-Opportunities:
like: JobName, Department, Description, etc..
These should be listed on a page. In ASP.NET I would use something like a Repeater, etc.. with PageSize option and automatic paging.
In the Backend (Backoffice in Umbraco, I assume) there has to be an Insert/Edit/Delete Page with the corresponding input boxes, which are maintained by the company employees, not by web-developers.
Which route should I look at? I am completely stuck, is there an example anywhere?
Can I use my own data-tables, or could/should I use the Umbraco content tables for this?
Thank you,
Reinhard
Welcome to Umbraco.
If you choose to use a pre-existing database, you're going to need the following pieces:
an ORM to access read/write the data
a custom hive provider for that data to allow for Umbrace to read it as an entity
a custom tree to allow for editing and adding data in the backoffice
a macro to display the content on the frontend.
http://web-matters.blogspot.com/2011/11/umbraco-5-hive-provider-tree-editor.html
is a great place to start.
As you're probably picking up on, this is a lot of work.. so, most importantly: Are you trying to maintain two applications?
If so, do you really need to be able to edit the list in both applications? Your task would be much simpler if you only allowed editing from the other application, and displayed the read-only list using web services.
If not, ditch the custom database. Umbraco 5 is a full EAV/CR system, so unlike some CMS products, you'll be able to represent any rdbs structure you can imagine. The simplest way would be to create a custom document type with those properties to represent a job opportunity, and store those job opportunities on a new node in the content tab.
About document types: http://our.umbraco.org/wiki/how-tos/working-with-document-types