<input type="text" class="product-input js-product-tags" placeholder="Computer, devices, smartphone" />
<ul class="js-tags">
<li class="tag-options">
<span>CPU</span><div class="remove-tag js-remove-tag">X</div>
</li>
</ul>
这就是我的 html 标签代码的样子。请帮助我如何在没有 jquery Ajax 的情况下将这些跨度值传递给 Controller 并保存在数据库中?
最佳答案
如果您想要回发,请创建隐藏的 input
元素:
<input type="text" class="product-input js-product-tags" placeholder="Computer, devices, smartphone" />
<input type="hidden" name="tags" value="CPU" />
<input type="hidden" name="tags" value="RAM" />
<input type="hidden" name="tags" value="HARDWARE" />
<ul class="js-tags">
<li class="tag-options">
<span>CPU</span><div class="remove-tag js-remove-tag">X</div>
<span>RAM</span><div class="remove-tag js-remove-tag">X</div>
<span>HARDWARE</span><div class="remove-tag js-remove-tag">X</div>
</li>
</ul>
...其中 name="tags"
中的 tags
是您的参数名称:
[HttpPost]
public ActionResult Create(ICollection<string> tags) {
// ...
}
关于javascript - 如何获取在 span 中使用 javascript 创建的产品标签的值并将这些值传递给 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46666844/