How to bind knockoutjs value to MVC Action Link (id)

yohan.jayarathna picture yohan.jayarathna · Jan 27, 2013 · Viewed 11.8k times · Source

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

Answer

Darin Dimitrov picture Darin Dimitrov · Jan 27, 2013
<a data-bind="attr: { 'href': '@Url.Action("Edit", "Manager")/' + itemId() }" class="cssClass">
    Edit
</a>