Błażej Rejnowski
Błażej Rejnowski

Reputation: 259

Trouble with @Html.ActionLink

I try to do left-side bar but all time i get error "[HttpException (0x80004005):Detected a potentially dangerous value Request.Path coming from the customer". What is wrong with that?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.css" rel="stylesheet" />
<link type="text/css" rel="stylesheet" href="~/Content/bootstrap.css" />

<title>@ViewBag.Title</title>
</head>
<body>
 <div class="navbar navbar-inverse" role="navigation">
    <a class="navbar-brand" href="@ Url.Action("List","Person")">Aplikacja</a>
</div>


<div class="row">
    <div class="col-xs-2">
        <ul class="nav nav-pills nav-stacked span3">
            <li><a href="@Html.ActionLink("Przyklad1", "Navigator")">Przyklad </a></li>

        </ul>

    </div>
    <div class="col-xs-8">
        @RenderBody()
    </div>
</div>

</body>
</html>

Upvotes: 1

Views: 203

Answers (1)

Shyju
Shyju

Reputation: 218882

@Html.ActionLink generates the markup for an anchor tag. You do not want to set that as the href value of another anchor tag.

When razor executes your current code, It will try to generate markup like below

<a href="<a href='/Navigator'>Przyklad1</a>">Przyklad</a>

Which is clearly invalid!

Solution : Either simply use Html.ActionLink alone,

<li>@Html.ActionLink("Przyklad","Navigator", "YourControllerName")</li>

Or

use use Url.Action to set the href value of an anchor tag.

<li><a href="@Url.Action("Navigator","YourControllerName")">Przyklad </a></li>

Upvotes: 1

Related Questions