What are the options for returning a complex type from a view to a controller in ASP.NET MVC? - asp.net

I have a model named Order which has a property named Customer. The Customer is a complex object with id, name, balance, etc.
When passing the Order object to a view, the view can access the Customer object and its data as expected. However, when I post back to the Controller, the Order object is populated as expected, but the Customer object is null.
It would be nice if I could add a hidden field in the view for the Customer so it would be included in the post back, but I understand this works for single values not for complex types.
I suppose I could add all the Customer fields to the Order object, but before I do that, is there a way to include the complex object in the postback, or is there a better approach than consolidating the two objects into one by putting the individual Customer fields into the Order type?

Related

Get request data (GET) in a Symfony (5) formType without using data_class

I'm building a formType to filter products on a collection page. You can set multiple select boxes which makes other auto filled or unnecessary. I want to be able to manipulate the formType based on the data like when using a data_class object. I'm not using data_class because the search isn't a persisted object which is saved to the database. I'm using a GET form.
For example 2 select boxes:
category
productType
When setting a category makes some of the productTypes unnecessary. So i want to not show it.
To do so in the formType I need the data of the request (GET) but I can't find a way to do so.
To retrieve data from the form, you can use $form->getData().
As you're in a GET context, I suspect you can take advantage from FormEvents (take a closer look to POST_SET_DATA event) and get rid of values you don't need.
One other thing I would like to point out, is that you still can use some kind of object that's not persisted to DB, like DTO or whatever.
Forms and entities are not related anyhow, neither in the usage nor in the intentions.

Symfony axios pass only id or entire object?

I have a Booking entity which has a ManyToOne relationship with my Car entity. I use axios to post my data for creating a Booking. I'm not sure if it's better practice to pass my whole Car object to my create function inside my Controller or to only pass the Car's id to the route of the function (which then fetches the Car from my database thanks to Symfonys param converter). Or is there another way which is considered "best practice"?
It depends on your scenario and the way you want to use.
Whenever you have to create an object / row inside the database then you will have to pass the whole object. assuming that the cars has already been created inside the database and you only have to link the booking object with the car than i will prefer you to bind it using ids rather than placing the whole object.
If you place the whole car object than it will increase the retrieval performance but if someday the information of car is changed than you will have to change the information on every booking object in which you placed the car object but if you just bind it with the Car Id than it will always give user the latest information even if the info of Car has been changed.
I thought that it will reduce the performance of the application if we used Id but that is not the case the DBMS use indexing to manage the search and search through id takes not time. It performance is not an issue and yes if you pass a whole object than it will also consume more data (since a large amount of data will be uploaded).

Marketo REST API - is there a way to get all records of a custom object?

I created a custom object and i want to get all its existing records. Is there a way of doing that via the REST API? Seems like a very basic and simple operation but i couldn't find information about it anywhere.
As you say, it seems like a basic task, but in the reality, it is more complex indeed.
Unfortunately, the Get Custom Object endpoint (which is the only endpoint to fetch Custom Objects) requires the filterType and filterValues parameters to be present as well. Basically this means that you have to have some information about the queried objects beforehand.
Also, a further restriction is that the value of filterType can only be one of the “searchable” fields of the Custom Object, meaning that it has to be either a Link field or a Dedupe field. (These fields are listed under the searchableFields property in the response from the Describe Custom Objects endpoint.)
So as mentioned above, you have to know the values for at least one of the properties of your Custom Objects before you make the query.
With additional queries though, you can grab these required values.
Let's say, you have your Custom Object linked to the Lead Object, and the Link field is called Owner Email (with the REST API name being ownerEmail) which links to the Email Address field of the Lead Object. In this case you could set the filterType to ownerEmail and set the emails of the leads as filterValues.
Then it is up to you how you gather the emails of those Leads who has a Custom Object attached. Luckily the REST API won’t throw an error if you provide a value that has no corresponding Custom Objects.
If your Custom Object is linked to a Lead, it's a bit complex but you can do like this:
Create a smart list and filter with "Has You Custom Object"
Get the smart list with API (GET /rest/asset/v1/smartLists.json)
Based on this list of Leads, get all Custom Objects (see the other answer).

What is the syntax to add a column to the Custom Form list that shows where in WF it is used?

Super simple.
When viewing the list of Custom Forms in Setup, I want to add a column that shows where those Custom Forms are in use (or null if used nowhere).
This is similar in principle to viewing the list of fields, which has a list of forms on which those fields are used.
What is the syntax I can use to add the appropriate column(s) to the view?
As far as I know, there is no linkage in the backend that connects categories (custom forms) to their host objects. This is probably because the list could be massive and the query would take quite a while to execute as it would have to traverse every object in Workfront or each form would store every parent object ID.
Unfortunately, you can't even search for objects by associated category IDs, so if you wanted to build this yourself you would need to query each object and search its categories to see if your custom form appeared.

POST Complex objects to controller

I am working on an enterprise scale project where I have a self referencing table called categories as below. Also in my current model I am using following table associations to fetch data. ( using EF6).
I have M-M mapping tables in DB for above M-M relationships.
In my controller GET action result returns the model which has Ilist(all parent categories). Then when the user is selecting items (in view) I am using Ajax to retrieve Ilist for next subset of categories (by passing to controller by Id - return Json result) and dynamically show next to the parent select list as below. ( and I have up to 4 subsets)
As the user is selecting categories, I am using Ajax call to load related categories and create selectlist or dropdownlist dynamically as below:
My question is Since all these data is loaded through Ajax, how can I bind them to my parent model. How can I capture user selected data into one parent model when user is posting the from to controller.
I know I can use Ajax and use Json to capture & transfer to contoller , But I need to use modelview , Can I use partiview to overcome this ?
Please advise the available options..
The key is making sure the name values match the object hierarchy accepted by the post operation. This is certainly doable; it's difficult because several AJAX operations build the UI, but one operation processes it, so you have to ensure the data expressions match the object being posted back.
You can use Html.NameFor() as a workaround to ensuring the naming paths work OK. Collections can make this difficult.

Resources