admin管理员组文章数量:1205576
I have a method that looks like this
function endcall_click(leadid) {
document.location = '@Url.Action("index","dispo",new{id=leadid})/';
}
Of course it doesn't work because it treats "leadid" as a server side variable but I want to inject the javascript variable passed into the method.
I tried wrapping lead id in but that didn't work.
function endcall_click(leadid) {
document.location = '@Url.Action("index","dispo",new{id="<text>leadid</text>"})/';
}
Any ideas?
I have a method that looks like this
function endcall_click(leadid) {
document.location = '@Url.Action("index","dispo",new{id=leadid})/';
}
Of course it doesn't work because it treats "leadid" as a server side variable but I want to inject the javascript variable passed into the method.
I tried wrapping lead id in but that didn't work.
function endcall_click(leadid) {
document.location = '@Url.Action("index","dispo",new{id="<text>leadid</text>"})/';
}
Any ideas?
Share Improve this question asked Dec 2, 2010 at 6:18 EmadEmad 4,2005 gold badges33 silver badges36 bronze badges2 Answers
Reset to default 20You can't inject javascript variable to a script that is evaluated at the server simply because at the moment this script executes and generates the output this variable hasn't yet come to existence. The only way to achieve this is to manipulate the resulting string:
function endcall_click(leadid) {
document.location = '@Url.Action("index", "dispo")/' + leadid;
}
The drawback is that this assumes manipulating the routes in javascript and if you decide to change them on the server the code might break.
I finally found the solution (*.vbhtml):
<script type="text/javascript">
function razorsyntax() {
/* Double */
@(MvcHtmlString.Create("var szam =" & mydoublevariable & ";"))
alert(szam);
/* String */
var str = '@stringvariable';
alert(str);
}
</script>
本文标签: aspnet mvcembedding javascript variable within razor syntaxStack Overflow
版权声明:本文标题:asp.net mvc - embedding javascript variable within razor syntax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738708004a2108028.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论