Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.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# $(this.attr('name',newN)); //替换值 var type=$(this.attr('type'); //if(type.toLowerCase()=“text”){ //$(this.attr('value',''); //} //如果有其他类型,则替换为默认值 $(this).removeClass(“输入验证错误”); }); $trLast.after($trNew); //重新分配验证 //变量形式=$(“形式”) //.removeData(“验证器”) //.removeData(“不引人注目的验证”); //$.validator.unobtrusive.parse(表单); }); // 2. 去除 //$('a.remove').live(“单击”),函数(e){-->这是用于旧的jquery库 $('body')。在('click','remove',函数(e)上{ e、 预防默认值(); $(this.parent().parent().remove(); }); }); 函数SelectedIndexChanged(){ //标杆 document.demoForm.submit(); }_C#_Asp.net Mvc_Linq_Entity Framework 6 - Fatal编程技术网

C# $(this.attr('name',newN)); //替换值 var type=$(this.attr('type'); //if(type.toLowerCase()=“text”){ //$(this.attr('value',''); //} //如果有其他类型,则替换为默认值 $(this).removeClass(“输入验证错误”); }); $trLast.after($trNew); //重新分配验证 //变量形式=$(“形式”) //.removeData(“验证器”) //.removeData(“不引人注目的验证”); //$.validator.unobtrusive.parse(表单); }); // 2. 去除 //$('a.remove').live(“单击”),函数(e){-->这是用于旧的jquery库 $('body')。在('click','remove',函数(e)上{ e、 预防默认值(); $(this.parent().parent().remove(); }); }); 函数SelectedIndexChanged(){ //标杆 document.demoForm.submit(); }

C# $(this.attr('name',newN)); //替换值 var type=$(this.attr('type'); //if(type.toLowerCase()=“text”){ //$(this.attr('value',''); //} //如果有其他类型,则替换为默认值 $(this).removeClass(“输入验证错误”); }); $trLast.after($trNew); //重新分配验证 //变量形式=$(“形式”) //.removeData(“验证器”) //.removeData(“不引人注目的验证”); //$.validator.unobtrusive.parse(表单); }); // 2. 去除 //$('a.remove').live(“单击”),函数(e){-->这是用于旧的jquery库 $('body')。在('click','remove',函数(e)上{ e、 预防默认值(); $(this.parent().parent().remove(); }); }); 函数SelectedIndexChanged(){ //标杆 document.demoForm.submit(); },c#,asp.net-mvc,linq,entity-framework-6,C#,Asp.net Mvc,Linq,Entity Framework 6,我希望有人能帮助我。 需要时将提供更多信息。您的方法接受2个参数,但您只发布1个对象-列表。假设您要基于现有DeviceConfig构建新的DeviceConfig,则应将操作方法更改为以下内容: public ActionResult Edit(List<Device_Pricelist> device_Pricelists) { if (ModelState.IsValid) { try { var devi

我希望有人能帮助我。
需要时将提供更多信息。

您的方法接受2个参数,但您只发布1个对象-
列表
。假设您要基于现有DeviceConfig构建新的DeviceConfig,则应将操作方法更改为以下内容:

public ActionResult Edit(List<Device_Pricelist> device_Pricelists)
{
    if (ModelState.IsValid)
    {
        try
        {
            var deviceConfig = db.DeviceConfig.Find(device_Pricelists.First().Device_config_id);
            deviceConfig.device_type_id = 13;
            deviceConfig.Active = true;
            deviceConfig.VersionNr++;
            deviceConfig.Date = DateTime.Now;

            db.DeviceConfig.Add(deviceConfig);

            foreach(var item in device_Pricelists)
            {
                item.Device_config_id = deviceConfig.Device_config_id;
            }

            db.Device_Pricelists.AddRange(device_Pricelists);

            db.SaveChanges();
            TempData["SuccesMessage"] = "Data is Succesfully saved";
            return RedirectToAction("Index");
        }
        catch
        {
            TempData["AlertMessage"] = "Saving Data Failed, Try Again";
        }
    }
    return View(device_Pricelists);
}

Sry,我添加了错误的代码,现在添加了正确的代码。你说了你想要的,但你没有解释要修复什么?当前代码有什么问题?您希望它做什么?@ChetanRanpariya当前的问题是创建了一个新的配置id,但没有相应的数据(需要修复),并且设备配置数据被添加到旧的配置id。新版本NR也没有正确更新
@model List<ConcremoteDeviceManagment.Models.Device_Pricelist>

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm("Edit", "Home", FormMethod.Post))

{
    <h1>
        @Html.DisplayName("Edit Configuration")

    </h1>
    <h2>
      @*  @Html.DisplayFor(model => model.DeviceType.name)<br />*@dammit
    </h2>

    if (TempData["AlertMessage"] != null)
    {
        <p class="alert alert-danger" id="FailMessage">@TempData["AlertMessage"]</p>
    }
    @Html.ValidationSummary(true)
    @Html.AntiForgeryToken()
    <div>
        @*  <a href="#" id="addNew" class="btn btn-primary">Add New</a>*@
    </div>
    <table class="table table-hover" id="dataTable">
        <tr>
            <th class="table-row">
                @Html.DisplayName("BAS artikelnummer")
            </th>
            <th class="table-row">
                @Html.DisplayName("Beschrijving")
            </th>
            <th class="table-row">
                @Html.DisplayName("Aantal")
            </th>
            <th class="table-row">
                @Html.DisplayName("Bouw Volgorde")
            </th>
            <th class="table-row">
                <a href="#" id="addNew" class="btn btn-success">Add New Row</a>
            </th>
        </tr>
        @if (Model != null && Model.Count > 0)
        {
            int j = 0;
            foreach (var item in Model)
            {
                <tr>
                    @Html.HiddenFor(a => a[j].id)
                    @Html.HiddenFor(a => a[j].Device_config_id)
@*                    @Html.HiddenFor(a => a[j].Price_id)*@

                    <td class="table-row">
                        @Html.DropDownListFor(a => a[j].Price_id, (IEnumerable<SelectListItem>)ViewBag.SelectedCMI, null, new { @class = "form-control" })
                    </td>
                    <td class="table-row">
                            @Html.DisplayFor(a => a[j].Pricelist.description, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(a => a[j].Pricelist.description, "", new { @class = "text-danger" })
                        </td>
                    <td class="table-row">
                        @Html.EditorFor(a => a[j].amount, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(a => a[j].amount, "", new { @class = "text-danger" })
                    </td>
                    <td class="table-row">
                        @Html.EditorFor(a => a[j].assembly_order, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(a => a[j].assembly_order, "", new { @class = "text-danger" })
                    </td>
                    @*<td class="table-row">
                            @Html.DisplayFor(a => a[j].DeviceConfig.Date, new { htmlAttributes = new { @class = "form-control" } })
                        </td>*@
                    <td>
                        @if (j > 0)
                        {
                            <a href="#" id="remove" class="btn btn-danger">Remove</a>
                        }
                    </td>
                </tr>
                j++;
            }
        }
    </table>

    <input type="submit" value="Save Device Data" class="btn btn-primary" />
    <button onclick="location.href='@Url.Action("Index", "Home")';return false; " class="btn btn-primary">Back to list</button>

}
@section Scripts{
    @*@Scripts.Render("~/bundles/jqueryval")*@
    <script language="javascript">

        $(document).ready(function () {

            //1. Add new row
            $("#addNew").click(function (e) {
                e.preventDefault();

                var $tableBody = $("#dataTable");
                var $trLast = $tableBody.find("tr:last");
                var $trNew = $trLast.clone();

                var suffix = $trNew.find(':input:first').attr('name').match(/\j+/);
                $trNew.find("td:last").html('<a href="#" id="remove" class="btn btn-danger">Remove</a>');
                $.each($trNew.find(':input'), function (i, val) {
                    // Replaced Name
                    var oldN = $(this).attr('name');
                    var newN = oldN.replace('[' + suffix + ']', '[' + (parseInt(suffix) + 1) + ']', '[' + suffix + ']', '[' + (parseInt(suffix) + 1) + ']', '[' + suffix + ']', '[' + (parseInt(suffix) + 1) + ']');
                    $(this).attr('name', newN);
                    //Replaced value
                    var type = $(this).attr('type');
                    //if (type.toLowerCase() == "text") {
                    //    $(this).attr('value', '');
                    //}

                    // If you have another Type then replace with default value
                    $(this).removeClass("input-validation-error");

                });
                $trLast.after($trNew);

                // Re-assign Validation
                //var form = $("form")
                //    .removeData("validator")
                //    .removeData("unobtrusiveValidation");
                //$.validator.unobtrusive.parse(form);
            });

            // 2. Remove
            //$('a.remove').live("click", function (e) {   --> this is for old jquery library
            $('body').on("click", '#remove', function (e) {
                e.preventDefault();
                $(this).parent().parent().remove();
            });

        });
    </script>
    <script type="text/javascript">
        function SelectedIndexChanged() {
            //Form post
            document.demoForm.submit();
        }
    </script>
public ActionResult Edit(List<Device_Pricelist> device_Pricelists)
{
    if (ModelState.IsValid)
    {
        try
        {
            var deviceConfig = db.DeviceConfig.Find(device_Pricelists.First().Device_config_id);
            deviceConfig.device_type_id = 13;
            deviceConfig.Active = true;
            deviceConfig.VersionNr++;
            deviceConfig.Date = DateTime.Now;

            db.DeviceConfig.Add(deviceConfig);

            foreach(var item in device_Pricelists)
            {
                item.Device_config_id = deviceConfig.Device_config_id;
            }

            db.Device_Pricelists.AddRange(device_Pricelists);

            db.SaveChanges();
            TempData["SuccesMessage"] = "Data is Succesfully saved";
            return RedirectToAction("Index");
        }
        catch
        {
            TempData["AlertMessage"] = "Saving Data Failed, Try Again";
        }
    }
    return View(device_Pricelists);
}
var oldN = $(this).attr('name');
var idx = parseInt(oldN.substr(1, oldN.indexOf(']')));
var newN = oldN.replace('[' + idx + ']', '[' + (idx + 1) + ']');