我的页面顶部有一个表格,下面有3个标签。当您单击表中的某一行时,它会从该行获取一个ID,将其存储在全局变量中,然后刷新第一个选项卡。我需要将该ID作为参数传递给该选项卡的幕后控制器。调用action方法但参数始终为null。我有一个获取ID的函数,在这个函数中我提醒它并且它确实有正确的ID,但由于某种原因,幕后操作总是将参数设置为null。
// action that is getting called but the parameter 'id' is always null
public PartialViewResult GetPriceDetail(string id)
{
return PartialView("_Price");
}
<script>
// global var to store the last id
var ID = -1;
// when this does the alert the ID is correct. it is the one I clicked on the table
function GetID(){
alert("Inside GetID() = " + ID);
return ID;
}
$("#tabs").tabs({
load: function(event, ui){
},
beforeLoad: function(e, ui){
ui.ajaxSettings.id= GetID();
}
});
// called when you click the first cell of each column since they are links with ID's
function ShowParams(id) {
ID = id;
// highlight the row in the table that has this value to show it's selected
$("#simHeaderTable").find("tr").each(function () {
var tdID = $(this).find("td:first-child").text();
if (tdID == ID){
$(this).children("td").css("background-color", "#FFFF66");
}
else
$(this).children("td").removeAttr("style");
});
// reload the Price tab now that we have set the ID
$("#tabs").tabs("load", 0);
}
</script>
以下是李的样子。不确定这是否与它有关。
<li><a href='@Url.Action("GetPriceDetail", "Home")'>Price</a></li>
答案 0 :(得分:0)
您是否尝试在GetPriceDetail方法中将数据类型从字符串更改为int?
答案 1 :(得分:0)
通过构建url以获取参数来解决此问题:
beforeLoad: function(e, ui){
ui.ajaxSettings.url += ( /\?/.test( ui.ajaxSettings.url ) ? "&" : "?" ) + 'id=' + ID;
}
不激动,但它适合我的情况。