You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

商品编辑功能异常求助:无法保存及编辑问题排查

商品编辑功能异常问题描述

我在商品编辑功能上遇到了异常:之前该功能能操作但无法保存,现在连编辑操作都完成不了,试了各种方法都解决不了。我有两个商品模型,Product仅用于查询,ProductInsert用于创建新商品,后者包含查询接口没有的属性。

Update方法代码

public async Task<Product> Update(string products, ProductInsert product, RootobjectInsert root)
{
    ProductInsert produtocriado = new ProductInsert();
    produtocriado.sku = products;

    RootobjectInsert raiz = new RootobjectInsert()
    {
            product = new ProductInsert()
        {
            sku = product.sku,
            active = product.active,
            price = product.price,
            qty = product.qty
        }
    };
    var client = new HttpClient
    {
        BaseAddress = new Uri("https://manairadigitalteste.conectala.com.br")
    };
    try
    {
        client.DefaultRequestHeaders.Add("x-user-email", "victor@test.com.br");
        client.DefaultRequestHeaders.Add("x-api-key", "eyJ0eXAiOiJKV1Q");
        client.DefaultRequestHeaders.Add("x-store-key", "1");
        client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Put, "app/Api/V1/Products/" + product.sku);

        string jsonObjeto = JsonSerializer.Serialize(raiz);
        req.Content = new StringContent(jsonObjeto, Encoding.UTF8, "application/json");
        using var res = await client.SendAsync(req);
        //res.EnsureSuccessStatusCode();
        var responseBody = await res.Content.ReadAsStringAsync();
        var roots = JsonSerializer.Deserialize<Rootobject>(responseBody);
    }
    catch (Exception)
    {
        throw;
    }
    return null;
}
}
}

控制器代码

// GET: ProdutosController/Edit/5
public async Task<ActionResult> Edit(string product)
{
    var products = await _IProduto.GetOne(product);
    return View(products);
}

// POST: ProdutosController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(string products, ProductInsert product, RootobjectInsert root)
{
    try
    {
        _IProduto.Update(products, product, root);
        return RedirectToAction(nameof(Index));
    }
    catch
    {
        return View();
    }
}

报错截图

Error edit(update)

补充视图代码

@model IEnumerable<WebConsumoApi.Models.Product>

@{
    ViewData["Title"] = "Index";
}

<h1>Index</h1>

<p>
    <a asp-action="Create">创建新商品</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.sku)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.name)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.description)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.status)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.qty)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.price)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.list_price)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.weight_gross)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.weight_liquid)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.height)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.width)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.length)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.items_per_package)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.brand)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ean)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
@foreach (var item in Model) {
        <tr>
            <td height="10">
                @Html.DisplayFor(modelItem => item.sku)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.description)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.status)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.qty)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.price)
            </td>
            <td>
                @Html.DisplayFor(modelItem => model.list_price)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.weight_gross)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.weight_liquid)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.height)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.width)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.length)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.items_per_package)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.brand)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ean)
            </td>
            <td>
                @Html.ActionLink("编辑", "Edit", new { product = item.sku }) |
                @Html.ActionLink("详情", "Details", new { product = item.sku }) |
                @Html.ActionLink("删除", "Delete", new { product = item.sku })
            </td>
        </tr>
}
    </tbody>
</table>

内容的提问来源于stack exchange,提问作者VICTOR MARCONI SANTOS DE OLIVE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 08:24:20