I’m a newcomer to MVC (having inherited a razor MVC web site).
I’m trying to get an About Us page to work with a tab style – buttons basically, to flick the content.
I added the following constructor and property …
public class AboutModel
{
public AboutModel(string selectedAboutTab)
{
SelectedAboutTab = selectedAboutTab;
}
private string _selectedAboutTab;
public string SelectedAboutTab
{
get { return _selectedAboutTab ?? "about"; }
set
{
_selectedAboutTab = value;
}
}
and then hoped to use HTML like this to change the tab …
<a href="/About?selectedAboutTab=directors">directors</a>
But it doesn’t seem to be passing anything to the Constructor.
I think the problem is in the Home Controller … which is on the Home Page – that kicks off the AboutModel in the first place … but I was thinking once I’d navigated from the ‘Home Page’ to the ‘About Us’ it’s job would be done! But it actually creates a new Model every time I click on an About ‘tab’ within the ‘About Us’ page.
This is the bit of code on the Home Controller.
public virtual ActionResult About()
{
ViewBag.CurrentPage = MenuPages.About;
return View(new AboutModel("about"));
}
Sorry for my clear lack of MVC knowledge! but could someone please tell me the easiest way I can get the SelectedAboutTab property populating?
Thanks
I just needed to add the selectedAboutTab to the Home Controller …