Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  95] [ 3]  / answers: 1 / hits: 19666  / 9 Years ago, wed, december 2, 2015, 12:00:00

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?


More From » asp.net-mvc

 Answers
75

Use @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;
}

[#64204] Sunday, November 29, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
luzv

Total Points: 178
Total Questions: 105
Total Answers: 114

Location: Palau
Member since Tue, May 30, 2023
1 Year ago
;