Q:

how to pass id across tabs in mvc razor view

I have an mvc view with multiple bootstrap tabs. Once i clicked on save in the first tab an entry will be generated in the database and an id (identity key in the db) will be generated. When i click on the next tab (i use the jQuery click event) i want to pass the id generated from the first tab. 
 @model MyProject.ViewModels.MydatabaseMyVM
 <div class="container">   
<div class="row">
    <h2>
        Create Staff</h2>
</div>
@using (Html.BeginForm())
{
<ul id="datatabs" class="nav nav-tabs nav-justified">
        <li class="active"><a data-toggle="tab" href="#details" id="TabDetailsLink">Personal
            Details</a></li>
        <li><a data-toggle="tab" href="#Tab1" id="TabTab1Link">Tab1</a></li>
        <li><a data-toggle="tab" href="#Tab2" id="TabTab2Link">Tab2</a></li>
        <li><a data-toggle="tab" href="#Tab3" id="TabTab3Link">Tab3</a></li>
    </ul>

 var data = $form.serialize(); $.post(url, data).done(function () {}. 

In my first tab i have fields from the student model, there is an id which will get generate from the database. On save of that i want to retain that id and when i click on another tab the id should pass to the action through ajax call.
I am using mvc 4 razor view and Bootstrap tab.
Can someone please guide me on how to pass the id generated at database from one tab to another. EF is used for accessing database

A:

If I understand correctly, on first tab, when you click Save, you post the form using ajax to StaffCreate(), which in terms return a view (not so sure why you are returning a View, but I will assume it is used else where).
Is it not possible when you post to StaffCreate(), you save the staffId in a session.
Then when you click second tab, in your jquery click event, first do a get request to a Action which just return staff Id as Json Result, once you got the id, do what ever you want with it.
So a pseudo code something like:
// your current action
[HttpPost]
public ActionResult StaffCreate(MydatabaseMyVMstaffvm)
{
    // previous omitted for simplicity

        Staff objStaff = MyService.StaffCreate(staffvm.Staff);
      
        Session["StaffId"] = objStaff.StaffID;
    // reset omitted for simplicity
}

Action for getting the StaffId
public ActionResult GetCreatedStaffId()
{
    return Json(Session["StaffId"], JsonRequestBehavior.AllowGet)
}

// your tab click event
$("").click(function{
    $.getJSON( "@Url.Action("GetCreatedStaffId")", function( data ) {
        // data is your StaffId
    }
})

Method 2 Psuedo code Store StaffId in hidden input
in the view which you return in StaffCreate(), do something like
<input type="hidden" id="hidStaffId" value="@Model.Staff.StaffID" />

your tab click event
// your tab click event
$("").click(function{
    var staffId = $("#hidStaffId").val();
})

