I have below javascript function in my MVC application,
function EditProducts(productId, orderId, employeeId, mode)
{
mode = "edit";
debugger;
var url = '@Url.Action("Index", "Home", new { productId = "__productId__", orderId = "__orderId__", employeeId = "__employeeId__", Mode = "__mode__"})';
var params = url.replace('__productId__', productId).replace('__orderId__', orderId).replace('__employeeId__', employeeId).replace('__mode__', mode);
window.location.href = params;
}
But it doesn't work. Here is my controller code by I am not getting any values in below vaiables,
public ActionResult Index(int productId, int orderId, int employeeId, string mode)
{
return View();
}
Any ideas on how to pass multiple parameters through url.action?
I have below javascript function in my MVC application,
function EditProducts(productId, orderId, employeeId, mode)
{
mode = "edit";
debugger;
var url = '@Url.Action("Index", "Home", new { productId = "__productId__", orderId = "__orderId__", employeeId = "__employeeId__", Mode = "__mode__"})';
var params = url.replace('__productId__', productId).replace('__orderId__', orderId).replace('__employeeId__', employeeId).replace('__mode__', mode);
window.location.href = params;
}
But it doesn't work. Here is my controller code by I am not getting any values in below vaiables,
public ActionResult Index(int productId, int orderId, int employeeId, string mode)
{
return View();
}
Any ideas on how to pass multiple parameters through url.action?
Share Improve this question asked Dec 2, 2015 at 2:48 AMehAMeh 2114 gold badges6 silver badges18 bronze badges 4 |3 Answers
Reset to default 15Use @Html.Raw to prevent the ampersand from being converted to &
inside javascript code
function EditProducts(productId, orderId, employeeId, mode)
{
mode = "edit";
debugger;
var url = '@Html.Raw(Url.Action("Index", "Home", new { productId = "__productId__", orderId = "__orderId__", employeeId = "__employeeId__", Mode = "__mode__"}))';
var params = url.replace('__productId__', productId).replace('__orderId__', orderId).replace('__employeeId__', employeeId).replace('__mode__', mode);
window.location.href = params;
}
Get the base url to the action method using Url.Action
helper method and add the querystring params to that.
This should work fine
$(function(){
var productId = 23;
var employeeId = 44;
var orderId = 34;
var mode = "tes";
var url = '@Url.Action("Index", "Post")';
url += '?productId=' + productId + '&orderId=' + orderId +
'&employeeId=' + employeeId + '&mode=' + mode;
window.location.href = url;
Only Converted the numbers to string
function EditRoles(companyid, roleid) {
//debugger;
var url = '@Html.Raw(Url.Action("EditRol", "Rol", new { companyID = "__companyid__", roleID = "__roleID__"}))';
var params = url.replace('__companyid__', companyid.toString()).replace('__roleID__', roleid.toString());
window.location.href = params;
}
params
(use console.log(params);` to check the output) – user3559349 Commented Dec 2, 2015 at 2:51