Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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
Asp.net mvc 3 如何将asp.net mvc3数据批注用于对象列表_Asp.net Mvc 3_Razor_Data Annotations - Fatal编程技术网

Asp.net mvc 3 如何将asp.net mvc3数据批注用于对象列表

Asp.net mvc 3 如何将asp.net mvc3数据批注用于对象列表,asp.net-mvc-3,razor,data-annotations,Asp.net Mvc 3,Razor,Data Annotations,这是我的模型 public class ContractsViewModel { public int Id { get; set; } public string Code { get; set; } public List<ContractProductItemViewModel> Products { get; set; } public ContractsViewModel() {

这是我的模型

public class ContractsViewModel
    {
        public int Id { get; set; }
        public string Code { get; set; }
        public List<ContractProductItemViewModel> Products { get; set; }
        public ContractsViewModel()
        {
            this.Products = new List<ContractProductItemViewModel>();
        }
    }

    public class ContractProductItemViewModel
    {
        public int Id { get; set; }
        [Required]
        public int? ProductId { get; set; }
        [Required]
        public double Price { get; set; }
        [Required]
        public int Quantity { get; set; }
    }
public class ContractsViewModel
{
公共int Id{get;set;}
公共字符串代码{get;set;}
公共列表产品{get;set;}
公共合同VIEWMODEL()
{
this.Products=新列表();
}
}
公共类ContractProductItemViewModel
{
公共int Id{get;set;}
[必需]
public int?ProductId{get;set;}
[必需]
公共双价{get;set;}
[必需]
公共整数数量{get;set;}
}
这是合同视图:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <div class="fieldset">
        <div class="editor-label">
            @Html.LabelFor(model => model.Code)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Code)
            @Html.ValidationMessageFor(model => model.Code)
        </div>
        <div class="new-detailitem">
            <div class="new-icon"></div>
            <div>Crear Nuevo</div>
        </div>
        <div>
            <table class="tblindex detail">
                <thead>
                    <td class="quantity">Cantidad</td>
                    <td>Grupo</td>
                    <td>Articulo</td>
                    <td class="price">Precio</td>
                    <td>SubTotal</td>
                    <td></td>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
    </div>
}

@使用(Html.BeginForm()){
@Html.ValidationSummary(true)
@LabelFor(model=>model.Code)
@EditorFor(model=>model.Code)
@Html.ValidationMessageFor(model=>model.Code)
新克雷尔酒店
康蒂达
格鲁波
关节
普里西奥
小计
}
这是productDetail视图

@{
    Layout = null;
    if (this.ViewContext.FormContext == null)
    {
        this.ViewContext.FormContext = new FormContext();
    }
}

<tr>
    <td class="quantity">
        @Html.TextBoxFor(model => model.Quantity)
        @Html.ValidationMessageFor(model => model.Quantity)
    </td>
    <td class="category"></td>
    <td class="product">
        <div>
            <span style="float:left"></span>
            @Html.HiddenFor(model => model.ProductId)
            <div class="getitem"></div>
            <div style="clear: both"></div>
        </div>
        @Html.ValidationMessageFor(model => model.ProductId)
    </td>
    <td class="price">
        @Html.EditorFor(model => model.Price)
        @Html.ValidationMessageFor(model => model.Price)
    </td>
    <td>0.00</td>
    <td><div class="removeicon"/></td>
</tr>
@{
布局=空;
if(this.ViewContext.FormContext==null)
{
this.ViewContext.FormContext=新的FormContext();
}
}
@Html.TextBoxFor(model=>model.Quantity)
@Html.ValidationMessageFor(model=>model.Quantity)
@Html.HiddenFor(model=>model.ProductId)
@Html.ValidationMessageFor(model=>model.ProductId)
@EditorFor(model=>model.Price)
@Html.ValidationMessageFor(model=>model.Price)
0
我使用jQueryAjax以编程方式添加每个项目详细信息行

我有一个问题,productdetail视图中的html.EditorFor和ValidationMessageFor为每一行生成相同的ID,而在客户端中,事件的处理方式不正确

我做错了什么? 解决这个问题的最佳方法是什么

谢谢