javascript - How best to pass an input text field across ajax tabs? -


experienced .net developer complete asp mvc (and web dev in general) novice. i'm looking best practice architecture suggestions how should accomplish following.

i have 3 jquery-ui tabs: first has input textbox: <input type="text" name="username" \>. others loading different page via ajax (implicitly using jquery) need know value of input field. how can retrieve value asp mvc controller of tab 2 or 3? fundamentally bad approach?

~/views/shared/_layout.cshtml:

<!doctype html> <html> <head>     @styles.render("~/content/themes/base/css", "~/content/css")     @rendersection("head", required: false) </head> <body>     @renderbody() </body> </html> 

~/views/demo/index.cshtml:

@{     layout = "~/views/shared/_layout.cshtml"; }  @section head {     <link rel="stylesheet" href="@url.content("~/content/themes/base/jquery.ui.all.css")" />     <script src="@url.content("~/scripts/jquery-1.6.2.js")"></script>     <script src="@url.content("~/scripts/jquery-ui-1.8.11.js")"></script>     <script>         $(function() {             $("#tabs").tabs();         });     </script> }  <div id="tabs">     <ul>         <li><a href="#tab1">tab 1</a></li>         <li><a href="/tab2">tab 2</a></li>         <li><a href="/tab3">tab 3</a></li>     </ul>     <div id="tab1">         <p>want able value of input field below tab2 , tab3</p>         <input type="text" name="username" />     </div> </div> 

~/controller/tab2controller.cs:

using system.web.mvc;  namespace mvcapplication1.controllers {     public class tab2controller : controller     {         public actionresult index()         {             //  want replace line 1 takes value of             //  input text box , queries model real data             viewbag.mylist = new[] { "1", "2", "3" };             return view();         }     } } 

~/views/tab2/index.cshtml

@{     layout = null; }  <ul>     @foreach (var obj in viewbag.mylist)     {         <li>@obj</li>     } </ul> 

thanks.

change controller action receive username.

public class tab2controller : controller {    public actionresult index(string username)    {        //  want replace line 1 takes value of        //  input text box , queries model real data         viewbag.mylist = new[] { "1", "2", "3" };          return view();     } } 

update href of tabs (2 & 3) on select event.

$(function() {    $("#tabs").tabs({       select: function(event, ui) {           if(ui.index == 1 || ui.index == 2) // if tab 2 or 3.           {             // select user name             var username = $("#tab1 input[name='username']").val();                                              if(username){                 var url = "/tab" + (ui.index + 1) + "?username=" + username;                 $("#tabs").tabs( "url" , ui.index , url );             }           }       }    }); }); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -