13

I have table view binds with knockoutjs model.

<tbody data-bind="foreach: items, visible: items().length > 0">
    <tr>
        <td data-bind="text: Title"></td>
        <td data-bind="text: Type"></td>
        <td data-bind="text: Author"></td>
        <td data-bind="text: Description"></td>
        <td data-bind="text: Time"></td>
        <td data-bind="text: Publisher"></td>
        <td data-bind="text: itemId"></td>
        <td>@Html.ActionLink("Edit", "Edit", "Manager", new {id = <knockoutjs model itemId value here>}, new {@class = "cssClass"})</td>
    </tr>       
</tbody>

I will explain the code. I have knockoutjs model which contains itemArray(items). I want to create actionlink and bind id value to (itemId) which is coming from knockoutjs model.

Hope you understand my issue

Thank you in advance

yohan.jayarathna
  • 3,423
  • 13
  • 56
  • 74

2 Answers2

24
<a data-bind="attr: { 'href': '@Url.Action("Edit", "Manager")/' + itemId() }" class="cssClass">
    Edit
</a>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

I'm not sure I understand what you're trying to do. But this code

<td>@Html.ActionLink("Edit", "Edit", "Manager", new {id = <knockoutjs model itemId value here>}, new {@class = "cssClass"})</td>

will not work, because knockout is a client side javascript, while the razor syntax is executed in the server and renders only html string.

Why not replace @Html.ActionLink with a normal html hyperlink

<a href="someurl" data-bind="attr: { href: Link }, text: SomeField"></a>
mdcuesta
  • 1,739
  • 1
  • 15
  • 17