Click here to Skip to main content
15,885,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a tab View with two tab pages on my view as:

C#
<div id="tab">
            <ul>
                <li><a href="#tabs-ViewBranch">View Branches</a></li><li><a href="#tabs-AddBranch">Add Branch</a></li>
            </ul>
            <div id="tabs-ViewBranch">
                    Tab page 1
            </div>
            <div id="tabs-AddBranch">
                @using (Html.BeginForm())
            {
                    @Html.ValidationSummary()
                    <p>Company Name: @Html.DropDownListFor(x => x.CompanyName, Model.CompanyNames, "Choose an option")</p>
                    <p>Branch Name: @Html.TextBoxFor(x => x.BranchName)</p>
                    <p>Branch Code: @Html.TextBoxFor(x => x.BranchCode)</p>
                    <p>
                        Branch Type:@Html.DropDownListFor(x => x.BranchType, Model.BranchTypes, "Choose an option")
                    </p>
                    <input type="submit" value="Save" />
                    <input type="button" value="Clear" />
                }
            </div>
        </div>


Suppose I have two ActionMethods as:

C#
public ViewResult A()
{
return View(A); //to TabPage 1 (#tabs-ViewBranch")
}
public ViewResult B()
{
return View(B); //to TabPage 2 (#tabs-ViewBranch")
}


Any idea how i can route them as desired?
Posted
Updated 29-Nov-15 20:53pm
v3
Comments
[no name] 30-Nov-15 2:51am    
<div id="tab">
<ul>
<li>View Branches</li>
<li>Add Branch</li>
</ul>
<div id="tabs-ViewBranch">
Tabpage 1
</div>
<div id="tabs-AddBranch">
Tabpage 2
}
</div>
</div>

1 solution

You can't. You need to use the PartialView for that. Something like following-
Tab headers-
HTML
<div id="tabs">
  <ul>
    <li><a href="#tabs-1">first tab</a></li>
    <li><a href="#tabs-2">second tab</a></li>
    <li><a href="#tabs-3">third tab</a></li>
  </ul>
  <div id="tabs-1">
    first tab content
  </div>
  <div id="tabs-2">
    second tab content
  </div>
  <div id="tabs-3">
    third tab content
  </div>
</div>

Tab contents-
HTML
<div id="tabs">
  <ul>
    <li><a href="#tabs-1">first tab</a></li>
    <li><a href="#tabs-2">second tab</a></li>
    <li><a href="#tabs-3">third tab</a></li>
  </ul>
  <div id="tabs-1">
    @Html.Partial("FirstTabView", Model)
  </div>
  <div id="tabs-2">
    @Html.Partial("SecondTabView", Model)
  </div>
  <div id="tabs-3">
    @Html.Partial("ThirdTabView", Model)
  </div>
</div>


-KR
 
Share this answer
 
Comments
[no name] 30-Nov-15 6:24am    
@KrunalRohit , Thank you for your help but you probably forgot to provide the link between ViewResults and Tabpages. I mean how do you connect them?
Krunal Rohit 30-Nov-15 23:34pm    
No viewresult. I'm talking about PartialViewResult.

-KR

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