1

这是我的控制器动作方法

public ActionResult ChangeStateId(int userId,int stateId)
 {
   return RedirectToAction("Index")    
 }

在我的 View 锚标记中,我想使用这样的参数值重定向到上述操作方法

<a href="'@Url.Action("ChangeStateId","User")?userId='+$('#hidID').val()+ '&stateId=' +$('#hidStateId'.val()")></a>;

但这对我不起作用。

4

2 回答 2

5

如果你想在 HTML 中工作,请试试这个,我已经放了静态值,你可以根据你的要求用动态转换它。

<a href="@Url.Action("ChangeStateId", "Home", new { userId = 1, stateId =2})" )>Click</a>

对于jQuery:

<a href="#" data_controller="Home" data_action="ChangeStateId"  id="ancChangeState">Click JQuery</a>

$("#ancChangeState").click(function () {            
        var controllerName = $(this).attr("data_controller");
        var actionName = $(this).attr("data_action");
        var userId = $('#hidID').val();
        var stateId = $('#hidStateId').val();

        if (userId == undefined)
        {
            userId = 1;
        }
        if (stateId == undefined) {
            stateId = 1;
        }        
        var url = "/"+controllerName + "/" + actionName +"?userId="+userId+"&stateId=" +stateId+" ";

        window.location.href = url;
    });
于 2016-08-23T08:43:19.840 回答
3

使用这个a标签:

<a id="GoToRedirectAction" data-url="@Url.Action("NewTelegramHlink", "Hlink",null, Request.Url.Scheme)">Go To Redirect Action</a>

使用这些jQuery代码:

$(document).ready(function() {
    $('a#GoToRedirectAction').click(function() {
        window.location.href = $(this).data('url') + "?userId=" + $('#hidID').val() + "+&stateId=" + $('#hidStateId').val();;
    });
});

或者

$(document).ready(function() {
    $('body').on("click",'a#GoToRedirectAction',function() {
        window.location.href = $(this).data('url') + "?userId=" + $('#hidID').val() + "+&stateId=" + $('#hidStateId').val();;
    });
});
于 2016-08-23T08:37:10.227 回答