@Html.ActionLink with data-bind

1,226 views
Skip to first unread message

Krishna Acharya

unread,
Feb 20, 2013, 10:44:32 AM2/20/13
to knock...@googlegroups.com
First.. is it possible to use @Html.ActionLink with knockout binding?

If yes, how would I write that?

This is what I need:

@Html.ActionLink( [I want display QuestionID() - a ko view model property] , "Question [controller action name]", "Project [controller name]", new { project = [here should be ProjectID() - a ko view model property]  id = [here should be QuestionID() - a ko view model property] }, new Dictionary<string, object> { { "data-bind", "title: 'View detailed question page'" } }))

In simple words, it should look like below when it renders:


Thanks in advance.

Gunnar Liljas

unread,
Feb 20, 2013, 11:22:13 AM2/20/13
to knock...@googlegroups.com
No.

ActionLink is a serverside concept, knockout is client side.

It would be possible to create a custom HtmlHelper (and perhaps some extra bindings) which would output a link with the correct bindings, but I don't know if it's really worth the effort. You can already use Url.Action to get the required base url, if you want that.

/G


2013/2/20 Krishna Acharya <acharya...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

Krishna Acharya

unread,
Feb 20, 2013, 11:32:43 AM2/20/13
to knock...@googlegroups.com
The problem is that @Html.ActionLink behaves perfectly fine, irrespective on my local machine or on deployed server.

But, anchor tag works only on local machine, whereas it gets cranky when I deploy the project to server, because server path is something like this:http://subsite.company.com/dept/subdept/and...now...comes...my...controller...and...then...action...

So,in anchor tag case case, system thinks http://subsite.company.com/ is my base url, not http://subsite.company.com/dept/subdept/  which is an issue.

That's why, if I can make @Html.ActionLink work with KO binding, I get the best of the both worlds.  But, it seems like, it's not possible easily, eh.  Oh well.

Did I make sense?

Gunnar Liljas

unread,
Feb 20, 2013, 11:44:51 AM2/20/13
to knock...@googlegroups.com
Url.Action will help you with the base url, which you can include in the binding.

<a data-bind="text:QuestionID,attr:{href:'@Url.Action("TheAction","TheController")?project=' + ProjectID()}"></a>
Reply all
Reply to author
Forward
0 new messages