2

Here is my controller Action method

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

and in my anchor tag of View, i want to redirect to above action method with parameter values like this

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

but it is not working for me.

Ramin Bateni
  • 16,499
  • 9
  • 69
  • 98
Steve
  • 352
  • 2
  • 6
  • 24

3 Answers3

6

If you wants to work in HTML please try this, I have put static value, you can convert it with dynamic as per your requirement.

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

For 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;
    });
3

Use this a Tag:

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

With these jQuery codes:

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

Or

$(document).ready(function() {
    $('body').on("click",'a#GoToRedirectAction',function() {
        window.location.href = $(this).data('url') + "?userId=" + $('#hidID').val() + "+&stateId=" + $('#hidStateId').val();;
    });
});
Ramin Bateni
  • 16,499
  • 9
  • 69
  • 98
0
HTML CODE

 <a href="#" onclick="viewAllOrder()" class="back-btn" style="float:right">View All</a>

JAVASCRIPT CODE
     function viewAllOrder() {
            var customerId = $("#ddlCustomer").val();
            var month = $("#ddlMonth").val().toString();
            var monthData = String(month);
            var salesOrg = $("#ddlSalesOrg").val();
            var url = "/Order/Index?CF="+"OD"+"&customerId=" + customerId + "&monthData=" + monthData + "&salesOrg=" + salesOrg;
            window.location.href = url;
        }
Prince
  • 277
  • 2
  • 16