2

我有 @Html.PagedListPager(Model, page => Url.Action("GetTabData", new { page })

在我的 js 文件中,我已经准备好使用myTab我需要与上面示例中的页面一起发送的变量。

我怎样才能做到这一点?

更新:我正在使用 js 变量来确定用户单击哪个选项卡,并根据该值查询数据。现在我已经实现了使用上面生成的链接的分页。有了这个,我发送 activeTab 的 ajax 调用被破坏了,我需要将此值与 Url.Action 上方的页面一起发送。

这是我用来通过 ajax 发送以确定用户单击哪个选项卡的 js 变量

$(function () {
    var activeTab = null;
    $('#tabs .tabLink').click(function (event) {
        var activeTab = $(this).attr('href').split('-')[1];
        GetTabData(activeTab);        
    });
    GetTabData(ommitted on purpse)

});
4

1 回答 1

0

I don't get the question clearly, but I am taking a guess here. Don't know if this is what you are looking for.

Note - You have GetTabData in both your javascript as well as cshtml code, I am hoping this is just coincidence, because the js function cannot be invoked via @Url.Action in this manner.

If you need to send two values as part of your URL, you could do it either in a RESTful way or have querystrings.

Option 1 -

Url.Action("GetTabData", new { page=2, tab="blah" })

Your corresponding controller action would look like

public ActionResult GetTabData(int page, string tab)
{
...
}

Option 2 - create a querystring and append it to the URL

/GetTabData?page=2&tab=blah

In this case the controller action would look like this

public ActionResult GetTabData()
{
    var params = Request.QueryString;
...
}
于 2013-03-29T08:20:20.983 回答