1

I'm trying to learn ASP.NET Core and writing simple project using Google Maps API and Infobox.js. In index.cshtml I've got default code:

<a asp-action="Place" asp-route-id="@item.Id">Edit</a>

And everything works, this code leads me to

localhost/places/Place/1

Now I would like to add simillar link to infobox contentString (id = 1):

google.maps.event.addListener(marker, 'click', function ()
{
contentString = '< a asp-action="Place" asp-route-id="' + id + '">detail< /a>';
boxText.innerHTML = contentString;
ibOptions.content = boxText;
var ib = new InfoBox(ibOptions); 
ib.open(map, marker);
map.panTo(ib.getPosition());
});

I can see the 'detail' label (it looks like a link - is blue and underlined) but i cannot click it - when I move mouse cursor over label - it does not change.

I write something like

contentString = '< a href="Place/' + id + '"> Details</a>';

It works (opens http://localhost/places/Place/1), but it is not the best way to do so, i think.

Could you help to change my code? Sorry for using quotation marks but I cannot do it another way.

Ariel Sz
  • 83
  • 1
  • 14
  • 1
    You can't do that. Tag Helpers are a Razor feature, not HTML feature. Tag helpers only work with views rendered by the server (which are processed by razor to be specific) – Tseng May 08 '17 at 16:05
  • Thank you for information. So what should I do to create an Url in infobox? I should use @Url.Action somehow? – Ariel Sz May 08 '17 at 16:08
  • 1
    @Url.Action is also a razor feature. Just use relative urls and set the base url in via `` inside your view or `_Layout.cshtml`. Your controllers are unlikely to change and even if they do, you'd have to rename it manually (whether you use `asp-action` or `asp-controller`) – Tseng May 08 '17 at 16:13
  • Thank you for your attention. I've added base href in _Layout.cshtml. What should I do in Javascript section? It should be as I shown previously: 'Details '; ? – Ariel Sz May 09 '17 at 06:07

0 Answers0