需要编写一个Jquery来获取所有的Selectlist选项值,将它们存储在一个数组中,并将它们发送给Action Me
Need to write a Jquery that gets all Selectlist option values, stores them in an array and post them to an Action Method
需要帮助编写一个Jquery,获取所有Selectlist选项数据值并将它们存储在数组/集合中。这个集合将在Ajax调用中发送给Action方法,Action方法将返回一个json对象/集合,我将把这个对象传递给为onsuccess指定的函数。
由于服务器上的某些原因,Action方法没有接收到数据。然而,当我用调试器检查javascript时,数组"arr"被填充。
public JsonResult GetPartPrice(int[] arr)
{
List<pidandprice> PidPriceList = new List<pidandprice>();
foreach (var pid in arr.Where(x => x != null ))
{
var Product = context.Products.First(x => x.ProductID == pid);
PidPriceList.Add(new pidandprice() { PartID = pid, Price = Product.ListPrice });
}
return Json(PidPriceList.Select(m => new {partid = m.PartID, price = m.Price}) );
}
<script type="text/javascript">
$(document).ready(function () {
var arr = new Array();
$('select option').each(function () {
arr.push($(this).val());
});
$.ajax({
type: "POST",
url: "http://localhost:50913/Customise/GetPartPrice",
data: arr,
success: function (data) { OnSuccess(data) }
});
});
function OnSuccess(data) {
alert(data.join(', '));
//This is where to write code to append
//all option names text with price difference
};
免费下载:http://jsfiddle.net/DavidLaberge/PyGey/8/
对于ajax,您可能希望使用$。帖子,美元。Get,或者$.ajax相关文章:
- 通过另一个php应用程序将我的项目推送到Github存储库中
- 将脚本缓存到本地存储的basket.js概念仍然是一个好主意吗
- 我该如何编写一个CouchDB视图,列出每个存储文档的大小
- Javascript使用本地存储,回调对象并用Json更改为一个字符串以用于填充函数
- 使用本地存储在一个页面上自动填写多个表单
- 我有一个javascript类和该类的对象,我想将该对象存储在本地存储中并检索它
- 制作一个阻止存储在浏览器历史记录中的网页
- 创建一个变量并在页面之间移动时“存储它”,jQuery
- 拆分一个句子并使用JavaScript将其存储在数组中
- 如何使用Javascript将表单数据存储到另一个页面的表中
- Javascript下载一个URL-Azure Blob存储
- 存储一个事件处理程序中的变量以供另一个事件处理器使用
- 需要将服务/工厂存储为一个值
- 在Javascript数组或一个对象中存储多个数据所需的Tweak
- Javascript——运行一个存储在JSON属性中的函数
- 为什么在flux应用架构中每个实体使用一个存储?
- 如何在extjs中创建一个存储在控制器中的实例
- ExtJS:连接一个存储到一个组合框
- 对相同类型的多个元素使用一个存储
- MobX -运行一个存储的构造函数在另一个