Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

WE are are using MVC5 razor , i have requirement to display multiple tabs and each tab has different data entry screen , each tab/screen belongs to different model.

I am able to display data in the tabs , but how to save data in individual tab and show that particular tab after saving.

As on post validation for other tabs failed as filling data in one tab and on post all other tab also posted.

Pleas suggest for this.
Posted
Updated 1-Oct-15 2:49am
v2
Comments
Krunal Rohit 1-Oct-15 5:18am    
make use of jQuery.

-KR
Nathan Minier 1-Oct-15 7:57am    
Are you using a display framework like bootstrap?
Member 11541057 1-Oct-15 8:05am    
Yes we are using Boostrap framework

Okay, using the bootstrap tabs, as described in http://getbootstrap.com/javascript/#tabs[^], You can put a different form with a different target controller/action on each form. That way each form will target a different model. Your easiest route is to create a partial view for each edit model action, and use that. Please bear with me, it's been awhile since I've done razor:

HTML
<div>

  <!-- Nav tabs -->
  <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#first" aria-controls="first" role="tab" data-toggle="tab">First</a></li>
    <li role="presentation"><a href="#second" aria-controls="second" role="tab" data-toggle="tab">Second</a></li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="first">
        @Html.RenderAction("GetMyFirstForm","MyController)
    </div>
    <div role="tabpanel" class="tab-pane" id="second">
        @Html.RenderAction("GetMySecondForm","MyController)
    </div>
  </div>

</div>


Form page, form section example:
HTML
@model MyNamespace.FirstModel
<div>
    @using(Html.BeginForm("EditMyFirstModel", "MyController", FormMethod.Post, 
                                      new { enctype = "multipart/form-data" }))
    {
        <!-- Needed fields here -->
        <input class="btn btn-default" type="submit" value="Submit" />
    }
</div>
 
Share this answer
 
v2
Comments
Member 11541057 1-Oct-15 9:45am    
I used in the same way you mentioned , but on click of submit both both tabs are loaded and for first it is showing Data validation messages , also on click of submit of 2nd tab it is not maintaining the tab
Nathan Minier 1-Oct-15 10:07am    
It's most likely the way that you're passing the model to the main view, then.

Make sure that you have a controller action that returns a partial view with the specific model that you want, rather than a big wrapper object and use the Html.RenderAction(). Updating to reflect.
You can use something like multi-step form (which has similar functionality that you're looking for).

http://codepen.io/atakan/pen/gqbIz[^]
http://www.jqueryrain.com/demo/jquery-step-form-wizard/page/2/[^]
http://webdesign.tutsplus.com/articles/build-a-multi-step-form-interface--webdesign-11715[^]

Loads of examples are there, you can modify it according to your need.

-KR
 
Share this answer
 
Comments
Member 11541057 1-Oct-15 12:59pm    
Hi Nathan,

Thanks for the suggestion , i got problem now using @Html.RenderAction both tabs are loading , on loading the page.
Also on click of Save button on second tab it is not maintaining the _Layout and it returns to indiviual PArtialView in page i return like
return PartialView("GetParameters", parameters);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900