如何根据隐藏字段值将查询字符串附加到 Url.Action 创建的 url
How to append a querystring to the url created by Url.Action base on a hidden fields values
这是我的控制器操作方法
public ActionResult ChangeStateId(int userId,int stateId)
{
return RedirectToAction("Index")
}
并且在我的 View 锚标记中,我想使用这样的参数值重定向到上面的操作方法
<a href="'@Url.Action("ChangeStateId","User")?userId='+$('#hidID').val()+ '&stateId=' +$('#hidStateId'.val()")></a>;
但它对我不起作用。
使用这个 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();;
});
});
如果你想在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;
});
这是我的控制器操作方法
public ActionResult ChangeStateId(int userId,int stateId)
{
return RedirectToAction("Index")
}
并且在我的 View 锚标记中,我想使用这样的参数值重定向到上面的操作方法
<a href="'@Url.Action("ChangeStateId","User")?userId='+$('#hidID').val()+ '&stateId=' +$('#hidStateId'.val()")></a>;
但它对我不起作用。
使用这个 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();;
});
});
如果你想在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;
});