admin管理员组文章数量:1391943
I have this method in my Controller that saves the value in a Tempdata, as shown below.
public Boolean SaveSession(string id) {
TempData["CurrentTab"] = id;
return true;
}
Now in my javascript, I want to get the value in that TempData. But when I alerted the value I got this value. "[object HTMLSpanElement]"
@{
if (TempData["CurrentTab"] != null){
@:alert("" + @TempData["CurrentTab"].ToString())
}
}
How can I get the string value of that Tempdata?
Thanks
I have this method in my Controller that saves the value in a Tempdata, as shown below.
public Boolean SaveSession(string id) {
TempData["CurrentTab"] = id;
return true;
}
Now in my javascript, I want to get the value in that TempData. But when I alerted the value I got this value. "[object HTMLSpanElement]"
@{
if (TempData["CurrentTab"] != null){
@:alert("" + @TempData["CurrentTab"].ToString())
}
}
How can I get the string value of that Tempdata?
Thanks
Share Improve this question asked Jun 12, 2013 at 5:44 RJ UyRJ Uy 3973 gold badges10 silver badges23 bronze badges1 Answer
Reset to default 2The problem is that you're wrapping your TempData
value incorrectly.
Assuming your id
is my_span
, the JavaScript output is:
alert("" + my_span)
When you probably want:
alert("my_span")
The reason you see [object HTMLSpanElement]
is because the Browser tries to translate my_span
into document.getElementById('my_span')
(since it doesn't know of any other my_span
) and you actually have such (span
) element with that id.
Try:
@{
if (TempData["CurrentTab"] != null){
@:alert('@(TempData["CurrentTab"])');
}
}
本文标签: aspnet mvc 3How to get the Tempdata in javascriptStack Overflow
版权声明:本文标题:asp.net mvc 3 - How to get the Tempdata in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744675608a2619089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论