Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net MVC中添加带有新项的子项?_C#_Asp.net_Asp.net Mvc_Entity Framework_View - Fatal编程技术网

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

C# 如何在asp.net MVC中添加带有新项的子项?,c#,asp.net,asp.net-mvc,entity-framework,view,C#,Asp.net,Asp.net Mvc,Entity Framework,View,我有简单的代码优先模型(图:) 我有一个问题,当我想增加一个新的法案。当我添加新账单时,我还想在账单上添加产品(将数据插入Pr_bi表) 我的账单实体: public class Bill : Entity { public string Number { get; set; } public DateTime TimeStamp { get; set; } public virtual Customer Customer { get; set; } publi

我有简单的代码优先模型(图:)

我有一个问题,当我想增加一个新的法案。当我添加新账单时,我还想在账单上添加产品(将数据插入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; }
}
我创建的视图模型如下所示:

    @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>}
@使用(Html.BeginForm(“Create”、“Bill”、FormMethod.Post、new{@class=“form horizontal”})){
@Html.HiddenFor(m=>m.ID)
票据编号:
@TextBoxFor(m=>m.Number,新的{@class=“form control”})
付款人:
@Html.EditorFor(x=>x.Payed)
客户:
@DropDownListFor(m=>m.Customer.ID,ViewData[“Customers”]作为SelectList,新建{@class=“form control”})
}
如何将产品添加到账单的创建视图中

我有什么,我喜欢什么:


谢谢你,祝你今天愉快

请添加您的UI屏幕您想显示什么?我已经添加了我拥有的和我想要的。请添加您的UI屏幕您想显示什么?我已经添加了我拥有的和我想要的
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>}