[英]jQuery append with html.ActionLink
I'm trying to append a Html.ActionLink
with jQuery like this 我试图像这样用jQuery附加
Html.ActionLink
a.append("<li>@Html.ActionLink("e-TCGB","Inbox","Folder",new { Type = "1",DocumentTypeId = "3" },null)+"</li>");
and it is giving errors. 它给出了错误。
Being very inexperienced in javascript and jQuery I don't know if the error is because of wrong string parameter or because of doing something very wrong. 在javascript和jQuery中经验不足,我不知道错误是由于错误的字符串参数还是因为做错了什么。
My guess is I'm making an escape character mistake but as I said, I don't know if what I'm doing is possible too. 我的猜测是我犯了一个转义字符错误,但正如我所说,我也不知道我在做什么也是可能的。
@Html.ActionLink is a helper method in MVC designed to be used in the Razor views. @ Html.ActionLink是MVC中的一个辅助方法,旨在在Razor视图中使用。 It is executed on the server and processed as the Razor view is rendered to HTML.
它在服务器上执行,并在Razor视图呈现为HTML时进行处理。
jQuery is a JavaScript library that is used on the browser so execution here happens after the HTML has been received by the browser. jQuery是浏览器上使用的JavaScript库,因此此处执行是在浏览器收到HTML之后进行的。
To recap, it is not possible to execute c# code (ActionLink) on the browser because it is a .net based server side method. 概括地说,由于它是基于.net的服务器端方法,因此无法在浏览器上执行c#代码(ActionLink)。
'Razor is compiled at runtime - meaning its already done doing it's thing before your jQuery code is executed. “ Razor是在运行时编译的-意味着在执行jQuery代码之前已经完成了它的工作。
You can simply use a hyperlink though: 您可以简单地使用超链接:
var li = $('<li>');
var link = $('<a href="/folder/inbox/?type=1?documenttypeid=3">e-TCGB</div>');
li.append(link);
a.append(li);
UPDATE: 更新:
Above, you can see two examples of generating elements using jQuery. 在上面,您可以看到两个使用jQuery生成元素的示例。 The first is shorthand for generating a new
<li>
element: 第一个是生成新的
<li>
元素的简写:
$('<li>');
The second is generating a hyperlink tag. 第二个是生成超链接标记。 If you want to add attribute information you can do so in a number of different ways however I prefer to just write the tag out in long form when generating the element:
如果要添加属性信息,可以用多种方法来实现,但是我更喜欢在生成元素时以较长的形式写出标签:
$('<a href="/folder/inbox/?type=1?documenttypeid=3">e-TCGB</div>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.