Razor template editor doesn't like my knockout binding syntax

I have an attr binding for a knockout that works fine:

<a data-bind="attr: { href: 'Action?destination=' + '@Model.Property' + '&entityId=' + Id }">Select</a>

However, syntax highlighting in Visual Studio throws an "Unterminated String Constant" error after any model property is inserted into the href string.

I experimented with "@ ()" and "@:", but nothing seems to make the editor happy.

+5
source share
2 answers

I had a similar problem when I wanted to pass the controller action URL (provided by the instance UrlHelperin the Razor view) for my viewmodel functions, which will be used later in jQuery AJAX calls.

, Visual Studio :

<button data-bind="click: function (data) { someFunction(data, '@Url.Action("SomeAction", "SomeController")') }">Action!</button>

, :

<button data-bind="@("click: function (data) { someFunction(data, '" + Url.Action("SomeAction", "SomeController") + "') }")">Action!</button>
+1

Html.ActionLink?

@Html.ActionLink("Action", "Select", new { destination = Model.Property, entityId = Model.Id });
-4

All Articles