Angularjs 在 MVC 剃刀内部

Angularjs inside MVC Razor

我是 angular 的新手,一直在做一些基本的事情。

我正在尝试将某些视图转换为使用 angular 但我卡住了

有人可以帮助我如何使用 angular

进行以下操作
<a href="@Url.Action("Details","Home",new { propertyID=item.RentalID,PropertyType="Rentals" })"><img data-original="img/property/pic (2).jpg" alt="@item.Description" src="@Url.Action("GetImage", "Home", new { id = item.RentalID })" class="img-hover"></a>

我想用数据中继器 {{i.Item}} 替换 "item" 例如

我已经试过了,但行不通

<a href="@Url.Action("Details","Home",new { propertyID={{i.RentalID}},PropertyType="Rentals" })"><img data-original="img/property/pic (2).jpg" alt="{{i.Description}}" src="@Url.Action("GetImage", "Home", new { id = {{i.RentalID }}})" class="img-hover"></a>

你不能,因为 @Url.Action 是在服务器上呈现的,而 angular 是稍后在客户端上完成的。

不过你可以试试这个:

<a ng-href="@Url.Action("Details","Home",new { PropertyType="Rentals" })&propertyID={{i.RentalID}}"><img data-original="img/property/pic (2).jpg" alt="{{i.Description}}" ng-src="@Url.Action("GetImage", "Home")?id={{i.RentalID}}" class="img-hover"></a>

请注意,我使用了 ng-href and ng-src,因为我们现在在 URL:

中使用动态属性

Using Angular markup like {{hash}} in an href attribute will make the link go to the wrong URL if the user clicks it before Angular has a chance to replace the {{hash}} markup with its value. Until Angular replaces the markup the link will be broken and will most likely return a 404 error. The ngHref directive solves this problem.