asp.net mvc 3 - How to get the Tempdata in javascript? - Stack Overflow

I have this method in my Controller that saves the value in a Tempdata, as shown below.public Boolean S

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 badges
Add a ment  | 

1 Answer 1

Reset to default 2

The 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"])');
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744675608a4587306.html

相关推荐

  • asp.net mvc 3 - How to get the Tempdata in javascript? - Stack Overflow

    I have this method in my Controller that saves the value in a Tempdata, as shown below.public Boolean S

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>