[英]HtmlBeginCollectionItem Get Current Item
I need: 我需要:
The problem is: how to change product informations in another view(other than Card) and reflect to the product of the card? 问题是:如何在其他视图(卡除外)中更改产品信息并反映到卡的产品上?
@using (Html.BeginCollectionItem("Products"))
{
@Html.HiddenFor(model => model.ClientID)
@Html.HiddenFor(model => model.ProductID)
<div class="card">
<img class="card-img-top" src="http://macbook.nl/wp-content/themes/macbook/images/png/iphone318x180.png" alt="Grupo Logo">
<div class="card-block">
<h4 class="card-title">@Model.Name</h4>
<p class="card-text">@Model.Desc</p>
<div class="btn-group">
<button type ="button" class="btn btn-primary open-modal" data-path="/Product/Edit/@Model.ProductID">Edit</button>
<button type="button" class="btn btn-primary open-modal" data-path="/Product/Features/@Model.ProductID">Features</button>
</div>
</div>
</div>
}
You can do this is another view (or by dynamically loading another view into a modal. The object has not been created yet, and since you using BeginCollectionItem()
to generate new items, any other view you used would not be using the same Guid
created by that helper so you would not be able to match up the collection items. 您可以在另一个视图中执行此操作(或通过将另一个视图动态加载到模式中来完成。该对象尚未创建,并且由于您使用
BeginCollectionItem()
生成新项目,因此您使用的任何其他视图都不会使用相同的Guid
由该助手创建,因此您将无法匹配收集项。
Instead, include the 'other' properties within the partial, but put them in a hidden element that gets displayed as a modal when you click the buttons. 取而代之的是,将“其他”属性包含在部分属性中,但将其放置在隐藏元素中,当您单击按钮时,该隐藏元素将以模态显示。
The basic structure of the partial for adding/editing a Product would be 用于添加/编辑产品的部分的基本结构为
<div class="product">
@using (Html.BeginCollectionItem("Products"))
{
@Html.HiddenFor(m => m.ClientID)
@Html.HiddenFor(m => m.ProductID)
<div class="card">
....
<button type ="button" class="btn btn-primary edit">Edit</button>
</div>
// Modal for editing additional data
<div class="modal">
@Html.TxtBoxFor(m => m.SomeProperty)
@Html.TxtBoxFor(m => m.AnotherProperty)
....
</div>
}
</div>
And then handle the buttons .click()
event (using delegation since the partials will be dynamically added to the view) to display the associated modal (assumes you have a <div id="products">
element that is the container for all Products) 然后处理按钮
.click()
事件(使用委派,因为会将部分对象动态添加到视图中)以显示关联的模式(假设您有一个<div id="products">
元素,该元素是所有Products的容器)
$('#products').on('click', '.edit', function() {
var modal = $(this).closest('.product').find('.modal');
modal.show(); // display the modal
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.