Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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
将每个对象的敲除传递给Html.HiddenFor_Html_Knockout.js - Fatal编程技术网

将每个对象的敲除传递给Html.HiddenFor

将每个对象的敲除传递给Html.HiddenFor,html,knockout.js,Html,Knockout.js,我需要在敲除的foreach循环中将对象的值传递到@Html.HiddenFor中。有可能吗?这是我的密码: <!-- ko foreach: Products--> <div class="well"> <h3> <strong data-bind="text: Name"></strong> <span class="pull-right label label-primary" dat

我需要在敲除的
foreach
循环中将对象的值传递到
@Html.HiddenFor
中。有可能吗?这是我的密码:

<!-- ko foreach: Products-->
<div class="well">
    <h3>
        <strong data-bind="text: Name"></strong>
        <span class="pull-right label label-primary" data-bind="text: formatCurrency(Price)"></span>
    </h3>

   @using (Html.BeginForm("AddToCart", "Cart"))
   {
        <div class="pull-right">
            @Html.HiddenFor(x=> x.ProductId)
            @Html.Hidden("returnUrl", Request.Url.PathAndQuery)
            <input type="submit" class="btn btn-success" value="Add to cart"/>
        </div>
    }

    <span class="lead" data-bind="text: Description"></span>
</div>
<!-- /ko -->


@使用(Html.BeginForm(“AddToCart”、“Cart”))
{
@Html.HiddenFor(x=>x.ProductId)
@隐藏(“returnUrl”,Request.Url.PathAndQuery)
}

也许有类似的说法,因为我知道
@Html.HiddenFor
是在服务器上执行的,而Knockout是客户端执行的?我是MVC开发新手,不知道在这个特定视图中使用Knockout是否是一个好主意,也许我应该允许在服务器端呈现项目?

HiddenFor只是一个样板C,它生成标准HTML隐藏字段标记,在客户端呈现,并用C模型中的值填充。它的ID可能为“ProductId”。它是JS代码可以针对的元素。在浏览器中查看完成页面的源代码,您将看到它。非常感谢!