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

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

Asked on December 24, 2018 in knockout js.
Add Comment


  • 2 Answer(s)

        Use this code to bind knockoutjs value to MVC Action Link (id)

    <a data-bind="attr: { 'href': '@Url.Action("Edit", "Manager")/' + itemId() }" class="cssClass">
        Edit
    </a>
    
    Answered on December 24, 2018.
    Add Comment

        The following Answer  is very useful in this case :

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

        The above will not work , This is due to the  knockout is a client side javascript , while the razor syntax is proceed in the server and provide only the  html string.

        Exchanging the  @Html.ActionLink with a normal html hyperlink is working in this case :

    <a href="someurl" data-bind="attr: { href: Link }, text: SomeField"></a>
    

    Answered on December 24, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.