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

前端 未结 2 1629
没有蜡笔的小新
没有蜡笔的小新 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:17

    I don't know how clever MVC's binding is since I use my own binding so I don't know whether it can do the binding to models for you.

    What you can do is to number all the inputs for each line. So Product1, 'Amount1`, etc. For each new line (say there is an 'Add Detail' button) you create a new set of inputs with the next available number.

    When you parse the Request.Form you simply ask for each line until you cannot find one --- then you know you are done.

    HTH

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题