how to implement Create action on Order and Order Details on single Create View?

前端 未结 2 1647
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 10:05

anyone came up with simple solutions?

question: Given the two model classes with a relationship of one-to-many, how can i design a single create for these..

2条回答
  •  甜味超标
    2021-01-07 10:38

    The short answer is really "it depends" :) The question you need to ask first (and it has nothing to do with MVC) is the following: when do you want to commit user entries? I can think of several options:

    • You have a "create order" page. User fills the header fields (looks like Member is the only one), hits save, you save order in the database, get the order ID, make the header fields read-only and the user starts entering lines.
    • The form has both header fields and detail fields on the entry form (personally, I find it confusing - but it's a matter of taste). You get all the data (probably in form collection) and build Order and Order details objects out of that (either in the controller, or through custom provider)

    Additionally, you need to answer the same question about order details. Do you want to submit every row, or allow the user to create multiple rows (through some "Add Row" button and JavaScript code behind it) and then submit a set of rows.

    Once you decide which way you want to go - it will be easier to design the form. If you run into problems - come back; I am sure you will get plenty of help!

    God luck

提交回复
热议问题