【发布时间】:2025-12-02 06:50:02
【问题描述】:
这是我的职责:
<script> function Calculate()
{
var ItemPrice = document.getElementById("price");
var weight = document.getElementById("weight");
var SelWeight = weight.options[weight.selectedIndex].value;
alert(SelWeight);
var Category = document.getElementById("SelectedCategory");
var SelCategory = Category.options[Category.selectedIndex].value;
alert(SelCategory);
}
</script>
我想让 SelCategories.Tax 和 SelCategories.Duty 将它们添加到重量值和总价中以在标签中显示总价。我正在使用 ASP.NET MVC 4 而这个是我想要使用的模型
public class CategoriesModel
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
public decimal Duty { get; set; }
public decimal Tax { get; set; }
public IEnumerable<SelectListItem> CategoriesList { get; set; }
}
【问题讨论】:
-
您应该有一个
controller和一个action method,它们将在客户端中提供您想要的数据。并且您可以进行 ajax 调用以从控制器操作中检索数据。 -
问题是另一个下拉列表是
<select>标签我将如何将选定的值传递给控制器?? -
我有 2 个下拉列表 1- 使用
<select>,第二个 2- 使用此模型 @MattBodily -
我发布的链接显示了如何获取任何下拉列表的选定项目,无论它是如何构建的,选择 id 或下拉列表的类。你的有什么不能用的吗?
标签: javascript asp.net asp.net-mvc asp.net-mvc-4