Turining An HTML into a link ASP.NET MVC

Я хотел бы чтобы иметь возможность превратить строки таблицы HTML в ссылки на контроллеры. Я понял что-то вроде

<td onclick="<%:Html.ActionLink("", "Index", new {id=item.user_id}) %>">

Я использую MVC 2

Спасибо.

1
задан Peter 17 August 2010 в 19:00
поделиться

1 ответ

<td onclick="window.location='<%:Url.Action("Index", new {id=item.user_id}) %>'">

The onclick attribute accepts some javascript code to execute. If you simply give it a URL, javascript doesn't know what to do with that.

In the snippet above, you're setting the window.location property to the desired URL. This causes the browser to go there.

EDIT: I also just realized that you were using the Html.ActionLink() method which actually generates an tag in your code. You'd be better off using the Url.Action() method, which actually generates a URL.

2
ответ дан 2 September 2019 в 22:04
поделиться
Другие вопросы по тегам:

Похожие вопросы: