Reputation: 55333
Is it possible to use AngularJS variable as Route Parameter in Razor Syntax like this?
<tr data-ng-repeat="job in jobs">
<td>
<a href="@Url.RouteUrl("editJob", new { id = job.JobID })">
<i class="glyphicon glyphicon-edit" style="color:#808080"></i>
</a>
</td>
</tr>
Right now I am using this.
<a href='@Url.Content("~/job/edit/"){{job.JobId}}'>
Upvotes: 3
Views: 5659
Reputation: 5638
I recommend neither solutions because mixing multiple templates is always a bit dangerous. The way our team solves this is
A bit like this (pseudo-code, example using ng-init)
<div ng-app="..." ng-init="config = { rootUrl: '@Url.Content("~/job/edit/")', otherValue: ''}">
<a href="{{config.rootUrl + job.JobId}}">...</a>
</div>
Upvotes: 1
Reputation: 17064
I'd say no, since Razor is rendered server side and at that time Angular variables don't exist. Meaning new { id = job.jobID }
will result in { id : null }
.
Your second solution is working because the angular string is concatenated right after the Razor part ends.
Upvotes: 5