通过Angularjs前pression /变量ASP.NET MVC行动的环节路由参数 [英] Pass Angularjs expression/variable to asp.net mvc action link as Route Parameter

查看:100
本文介绍了通过Angularjs前pression /变量ASP.NET MVC行动的环节路由参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何传递angularjs前pression / varibale到ASP.NET MVC ActionLink的?

How can we pass angularjs expression/ varibale to asp.net mvc actionlink ?

下面是我的asp.net mvc的ActionLink的code

Here is my asp.net mvc actionlink code

 @Html.ActionLink("{{row.x}}", "Details", "Info", new { id = "{{row.x}}" }, null)

在第一个参数{{row.x}}工作正常,因为它显示的价值,但是当作为路径参数传递它保留了自己作为{{row.x}}并不会evaulate.If我删除引号它不编译

In the first parameter {{row.x}} works fine as it displays value but when being passed as route parameter it retains itself as {{row.x}} and does not evaulate.If i remove quotes it doesnt compile.

推荐答案

剃须刀code执行在服务器上。所以,你不能传递你的客户端的角度变量作为 Html.ActionLink helper方法路线值字典参数。

Razor code executes at the server. So you cannot pass your client side angular variable as the route value dictionary parameter for the Html.ActionLink helper method.

你可以做的是在的href 价值建立与纯HTML链接的HTML标记并追加角度数据需要。您仍然可以使用 Url.Action helper方法建立正确的相对URL到信息操作方法。

What you can do is build the html markup for the link with pure html and append angular data in the href value as needed. You can still use Url.Action helper method to build the correct relative url to the Info action method.

<a href="@Url.Action("Info","Details")?id={{row.x}}">{{row.x}}</a>

这篇关于通过Angularjs前pression /变量ASP.NET MVC行动的环节路由参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆