Un Expected result while rendering @Html.ActionLink in the browser. Below are the code i written in jqGrid for displaying link column.
{ name: 'Restart',
formatter: function (cellvalue, options, rowObject) {
var x = '@Html.ActionLink( "Restart", "Dashboard", new { requestId ="myId" }, new { onclick = "return confirm('Are you sure to Restart?');" })';
return x.replace("myId",rowObject[8]);
}, align: 'left', width: 100
}
After rendering in the browser it displayed like this
<a href="/DashBoard/Dashboard?requestId=2362e13b-e4fc-4140-b7ad-1bd0e82b6bde" onclick="return confirm('Are you sure to Restart?');">Restart</a>
When I replace @Html.ActionLink( “Restart”, “Restart”) in the above code.It displays correctly like this.
<a href="/Dashboard/Restart?requestId=2362e13b-e4fc-4140-b7ad-1bd0e82b6bde" onclick="return confirm('Are you sure to Restart?');">Restart</a>
Why ASP.NET MVC4 produce Un Expected result? Is there any fix for this issue?
You shouldn’t consider this behaviour as unexpected. You are using following overload of LinkExtensions.ActionLink method:
So the second parameter is action name and controller name defaults to current controller.