views:

56

answers:

4

i have a temp data which i want to receive in javascript and then want to assign it to the tab selected? how would i do that?

var langid ="<% Tempdata["something"] %>";
$('#tabs').tabs('select', 'tabs' - langid);
A: 

I think the problem is you are missing a closing bracket.

var langid = <%: Tempdata["something"] %>;
$('#tabs').tabs('select', 'tabs' - langid);

I'm not sure what the syntax is for setting the tab text is though.

Barry
A: 

another thing to notice is in second line


var langid = <%: Tempdata["something"] %>;
$('#tabs').tabs('select', 'tabs-' + langid);

lakhlaniprashant.blogspot.com
A: 
<script>
alert('<%=TempData["something"] %>');
alert('<%=ViewData["someelse"]%>');
</script>

btw TempData uses Session, so probably you would like to stick with ViewData

Omu
A: 

Generally TempData is what you would use to pass messages between controllers, so in your case ViewData is a better fit, even though it is considered a better practice to use a property of a strongly typed model. Despite the fact, that this will work:

var langid ="<%= ViewData["something"] %>";
$('#tabs').tabs('select', 'tabs' - langid);

inline JavaScript in your view is not a good practice either. And if you later want to extract this code into a separate js file, it will break. I would recommend creating a hidden field to store the value in the HTML, and read it with jQuery.

In your View:

<input type="hidden" id="yourLangId" value="<%= ViewData["something"] %>" />

In your js:

var langid = $("#yourLangId").val();
$('#tabs').tabs('select', 'tabs' - langid);
Yakimych