如何实现单上的订单和订单详细信息创建动作创建视图? [英] how to implement Create action on Order and Order Details on single Create View?

查看:204
本文介绍了如何实现单上的订单和订单详细信息创建动作创建视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人想出了简单的解决方案?

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..

我怎样才能订单详细信息集合到未在数据库中尚未持久化一个订单实体?并且将我所用的ViewModels?
因为我有一个完整的表格订购页面(主),那么我必须有一个收集订单细节的局部视图之后,当我点击保存,将创建订单加上它的订单详情集合。谢谢

how can i add order details collection to a order entity that is not persisted yet in the database? and what viewmodels will i use? given that i have Order page(master) that is completed form then i must have a partial view that collects order details and after that when i clicked 'save', it will create the 'Order' plus its collection of 'order details'. thanks

的codeS一个简单的解决方案会有所帮助。谢谢

a simple solution of codes will be helpful. thanks

下面是我的模型:

public class Order
    {
        [Key]
        public int OrderID { get; set; }

        [DisplayFormat(NullDisplayText = "0.00")]
        public decimal TotalAmount { get { return OrderDetails.Sum(od => od.Amount); } }

        public decimal Cash { get; set; }

        [DisplayFormat(NullDisplayText = "0.00")]
        public decimal TotalBV { get { return OrderDetails.Sum(od => od.BV); } }

        public int MemberID { get; set; }

        public virtual Member Member { get; set; }

        public virtual ICollection<OrderDetail> OrderDetails { get; set; }
    }

public class OrderDetail
{
    [Key]
    public int OrderDetailID { get; set; }
    public int OrderID { get; set; }

    public decimal Amount { get { return Product.Price * Quantity; } }

    public decimal BV { get { return Product.BV * Quantity; } }

    public int Quantity { get; set; }
    public virtual Product Product { get; set; }
}

感谢。

推荐答案

简短的回答真的是这取决于:)这个问题你要问第一个(也是它无关MVC)如下:当你想提交用户条目?我能想到的几个选项:

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:


  • 您有一个创建订单页面。用户填写的头字段(貌似成员是唯一的一个),点击保存,保存为了在数据库中,拿到订单ID,使头字段只读和用户开始输入线。

  • 的形式同时具有头字段和报名表上详细字段(个人而言,我觉得困惑 - 但它是一个爱好问题)。你得到的所有数据(可能在形式的集合),并建立订单和订单细节的物品运到了(无论是在控制器,或者通过自定义提供)

此外,你需要回答有关订单的详细信息同样的问题。你想提交每一行,或者允许用户创建多个行(通过一些添加行按钮和JavaScript code后面),然后提交一组行。

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!

神运气

这篇关于如何实现单上的订单和订单详细信息创建动作创建视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆