如何在asp.net MVC中添加带有新项目的子项目?

时间:2019-03-31 11:19:42

标签: c# asp.net asp.net-mvc entity-framework view

我有一个简单的代码优先模型(图像:https://ufile.io/7c52a

我想添加新帐单时遇到问题。添加新帐单时,我还想在该帐单上添加产品(将数据插入Pr_bi表)。

我的账单实体:

public class Bill : Entity
{
    public string Number { get; set; }
    public DateTime TimeStamp { get; set; }

    public virtual Customer Customer { get; set; }
    public virtual ICollection<Product_Bill> Product_Bill { get; set; }
}

我的产品实体:

public class Product : Entity
{
    public string Name { get; set; }

    public virtual ICollection<Product_Bill> Product_Bill { get; set; }
}

我的pr_bi实体:

public class Product_Bill : Entity
{
    public int Quantity { get; set; }

    public virtual Bill Bill { get; set; }
    public virtual Product Product { get; set; }
}

我创建像这样的创建视图模型:

    @using (Html.BeginForm("Create", "Bill", FormMethod.Post, new { @class = "form-horizontal" })){
@Html.HiddenFor(m => m.ID)
<div class="form-group">
    <label class="col-sm-2 control-label">Bill number:</label>
    <div class="col-sm-6">
        @Html.TextBoxFor(m => m.Number, new { @class = "form-control" })
    </div>
</div>

<div class="form-group">
    <label class="col-sm-2 control-label">Payed:</label>
    <div class="col-sm-6">
        @Html.EditorFor(x => x.Payed)
    </div>
</div>

<div class="form-group">
    <label class="col-sm-2 control-label">Customer:</label>
    <div class="col-sm-6">
        @Html.DropDownListFor(m => m.Customer.ID, ViewData["Customers"] as SelectList, new { @class = "form-control" })
    </div>
</div>

<div class="form-group">
    <div class="col-sm-offset-2 col-sm-6"><input type="submit" value="Shrani" class="btn btn-default" /></div>
</div>}

如何在该帐单内添加产品以创建帐单视图?

我有什么,我喜欢什么: Screen

谢谢您,祝您愉快!

0 个答案:

没有答案