MVC child - parent on the same page - asp.net-mvc

I'm pretty new to using MVC3 so hopefully the terms I'm using are all correct.
Basically I'm looking for a way (if possible!) to have a parent and child(s) record be added on the same page. I'm able to get the page to display correctly, but I'm unsure how to update the parent model.
In my Create view I have all the fields for the parent, and I'd also like to add the child records to the form as well.
I'm currently using Html.RenderPartial("CreateChildView") to display my Create child page within the parent.
I'm also using Html.RenderPartial("IndexChildView) to display my child records that have been added.
Where I'm stuck at is how to update the Parent model from the "CreateChildView" from above,
I've tried adding a submit button to the child view but I'm not getting the results I was hoping for.
the equivelent c# code that I'm kind of looking for is:
ParentObject.ChildObject.Add(new ChildObject)
and then a way to display this correctly
Thanks in Advance

Place both partials in div with ids. Post data with ajax from "CreateChildView" and update "IndexChildView" with response.

Related

What is form collection in ZF2

What is ZF2 form collection ? When should we use form collection ? I think ZF2 document has no clear definition about Collection.
Can any one explain with the example?
Thanks for reading.
A Form Collection is used whenever your form is supposed to display multiple instances of a certain object.
For example: You have one Album-Object and you have a Track-Object. One Album is supposed to have multiple Tracks. Instead of adding just one Track per form you can create a collection to allow for multiple tracks to be added at once.

Dynamic linking gets cleared when inserting new records

I have one form in AX 2012 from which i am calling another child form which shows records that are related to the selected record in Parent form(Dynamic linking).
Now, when I am trying to create a new record in a child form, the dynamic linking between this form and its parent form gets cleared and child form starts showing all data according to its datasource and not any filtered records which I don't want.
I want to know that, how to get stick with that dynamic linking while creating new Record in a child form.
Check that your grids really belongs to the correct datasources. If not, strange things happen.

Partial Page Postback'ish MVC 4

First, I apologize if this is a dumb question, but I'm new to MVC and am trying to get up to speed as quickly as possible. I have spent hours searching for answers and even went and bought a book on MVC 4, but it still didn't answer my question.
I have a form I'd like a user to fill out to add a new product to the catalog. They choose the category, enter the name, a description, etc.. On the same page I'd like them to be able to add sizes or product options such as Small, Medium, Large, etc.. The problem is I'm not sure how to go about this.
I need to temporarily store the size options for example in some sort of collection until the user actually 'saves' the product, then I need to be able to read the collection. What I'm trying to avoid is to have the user add the basic product info, then save it, then select it, then choose to add options to it. I'm trying to just do it all on one form. Any help would be greatly appreciated!
There is nothing preventing you creating a view model with its own collections for the detail items and have those mapped to some sort of javascript control for selecting multiple items such as one that writes to an mvc hidden form control.
The controller handling the postback will simply create the master model from the postback data (the updated view model) and then create the child records. The whole thing could be achieved with ajax calling a controller action that returns a partial view of the updated ui.
Similar to this but have the list as a property of the master model
http://www.stevefenton.co.uk/Content/Blog/Date/201002/Blog/How-To-Handle-Multiple-Select-Lists-In-ASP-NET-MVC/
A little more advanced on how to manage your own bindings http://www.dotnetcurry.com/ShowArticle.aspx?ID=584
Sounds like u need to roll your sleeves up and get a control written in javascript that allows child items to be added client side whist serializing e.g. Into json when they save and saving it to an mvc hidden control ready for postback. Use json.net to hydrate these values into your pocos. http://erraticdev.blogspot.co.uk/2010/12/sending-complex-json-objects-to-aspnet.html

How to get the last inserted id of embed form and store it in parent form : symfony

I have to parent form called EventForm and embed form called as RegisterForm. If your is not logged in means i want to show register form. Registration working fine with embed form. But after registration i want to store user id to parent table event.
I guess saveEmbeddedFroms() function called after parent form saved. So which function is suitable to update parent form. Can any one give me idea. How to do this.
When you call $form->save() on a form it saves the embedded forms as well but the embedded forms are saved after the main object.
I think what you could do is to write a preSave() function for your main form in which yu can get the embedded form, perform a save() o it (which will give you in return the saved object) and manually set the userid in the main form (remember to unset the embedded form so it is not saved twice).
You could also rethink the whole model because it looks a bit complicated ;) Do you reaaly have to use embedded forms here?

ASPNET MVC what do you call this, a partial view? Or something else?

I'm trying to google for info on a situation, but I dont know what it is called, so its hard to find results :)
I have a model with say 10 fields. But only some of those are shown on a particular view, lets say 3 of them: id, name, date. What do you call this kind of view that does not display the whole model? A partial view?
The problem is that because 7 fields are not sent to the view, when the Update action is called on the controller, those fields are null, and the DB gets updated with those 7 fields set to null.
This is called a ViewModel, which is obtained from the Model and is more adapted to the View.
This is still a view.
You are not specifying what kind of storage are you using, I'll make an example using the entity framework, but you can do it with whatever method you like.
The model for the view is an Entity. When you display the form in your view, only part of the fields in your model are editable. When the user submits, therefore, your model has only several fields filled in.
So, you should retrieve a new copy of the object you are editing from the database (call it "fromDb"), copy only the edited fields into the fromDb object, and save the fromDb object instead.
This way, all the fields are preserved.
Another way to do this, is to render hidden fields for all the fields that are not present. However this is NOT secure, as the user could edit those fields by hand (using the developer tools, or firebug).

Resources