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);
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);
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.
another thing to notice is in second line
var langid = <%: Tempdata["something"] %>;
$('#tabs').tabs('select', 'tabs-' + langid);
<script>
alert('<%=TempData["something"] %>');
alert('<%=ViewData["someelse"]%>');
</script>
btw TempData uses Session, so probably you would like to stick with ViewData
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);