I’d like to be able to turn rows of an html table into links to controllers.
I figured something like
<td onclick="<%:Html.ActionLink("", "Index", new {id=item.user_id}) %>">
I’m using MVC 2
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
onclickattribute 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.locationproperty 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<a href=""></a>tag in your code. You’d be better off using theUrl.Action()method, which actually generates a URL.