本文介绍了如何对Url.Action语句中的参数进行变量处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MVC视图有一个网格和一个细节局部视图。当用户选择一行时,我需要显示详细的局部视图。细节局部视图将根据记录类型而不同。



这是当前代码:

var grid = $(#grdAlertList)。data(kendoGrid);

var row = grid.select();

var data = grid.dataItem(row);

$(#divAlertDetailList)。load( @ Url.Action(_ AlertDetailDisplay,AlertList,

new

{

inTenantId = TenantId,

instanceId =ActivityHistoryId

})。replace(TenantId&,data.TenantId +'&')。replace(ActivityHistoryId ,data.ActivityHistoryId),

函数(响应,状态,xhr){

if(status =='error')

alert(响应);

//其他

// _database.value = $(#divAlertDetailList.concat(row))[0] .children.item()。价值;

});

}



我想做的是:

@ Url.Action( _AlertDetailDisplay+ Record-Type ,AlertList,



我也愿意允许Javascript代码转到相同的控制器方法并让它返回正确的局部视图。



感谢您的帮助。



更新:找到解决方案。在Url.Action中使用占位符名称,然后对其进行替换。

$(#divAlertDetailList)。load (@ Url.Action(DynamicName,AlertList,

new

{

inTenantId =TenantId,

instanceId =ActivityHistoryId

})。replace(TenantId&,data.TenantId +'&')。

replace(ActivityHistoryId,data.ActivityHistoryId)。

替换(DynamicName,_ AlertDetailDisplay+ actionMethod),





其中actionMethod =代码中定义的JavaScript变量。

My MVC view has a grid and a detail partial view. When the user selects a row I need to have the detail partial view display. The detail partial view will be different based on the record type.

Here's the current code:
var grid = $("#grdAlertList").data("kendoGrid");
var row = grid.select();
var data = grid.dataItem(row);
$("#divAlertDetailList").load("@Url.Action("_AlertDetailDisplay", "AlertList",
new
{
inTenantId = "TenantId",
instanceId = "ActivityHistoryId"
})".replace("TenantId&", data.TenantId + '&').replace("ActivityHistoryId", data.ActivityHistoryId),
function (response, status, xhr) {
if (status == 'error')
alert(response);
//else
// _database.value = $("#divAlertDetailList".concat(row))[0].children.item().value;
});
}

What I would like to do is:
"@Url.Action("_AlertDetailDisplay" + Record-Type, "AlertList",

I am also open to allowing the Javascript code go to the same controller method and have it return the "proper" partial view.

Thanks for the assistance.

UPDATE: Found the solution. Used a placeholder name in the Url.Action and then did a replace on it.
$("#divAlertDetailList").load("@Url.Action("DynamicName", "AlertList",
new
{
inTenantId = "TenantId",
instanceId = "ActivityHistoryId"
})".replace("TenantId&", data.TenantId + '&').
replace("ActivityHistoryId", data.ActivityHistoryId).
replace("DynamicName", "_AlertDetailDisplay" + actionMethod),


where actionMethod = a JavaScript variable defined in the code.

推荐答案




这篇关于如何对Url.Action语句中的参数进行变量处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 12:32