使用 ASP.NET MVC3 razor 上的 javascript 变量动态创建 html 操作链接 [英] Dynamically create html action links using javascript variables on ASP.NET MVC3 razor
本文介绍了使用 ASP.NET MVC3 razor 上的 javascript 变量动态创建 html 操作链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个带有以下键值对的 javascript 字典变量:
Say I have a javascript dictionary variable with the following key value pairs:
var attributes = { name : "name1", age: 10}
我想使用上述属性中的值在相同的 javascript 函数中创建 HTML ul 元素的子元素,如下所示:
I want to use the values in the above attribute to create the children of an HTML ul element within the same javascript function as follows:
var htmlContent = '<ul><li>@Html.ActionLink(attributes["name"], "Details", "Home", new { name = attributes["name"]})</li></ul>'
有没有办法做到这一点?TIA.
Is there a way to do this? TIA.
推荐答案
我不确定您是否可以在 @Html.ActionLink
中使用 JavaScript attributes
变量?
I'm not sure you can use the JavaScript attributes
variable in the @Html.ActionLink
?
我建议将其更改为
var htmlContent = '<ul><li><a href="@Url.Action("Details", "Home")" name="' +
attributes.name + '">Link</a></li></ul>';
这篇关于使用 ASP.NET MVC3 razor 上的 javascript 变量动态创建 html 操作链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文