I'm trying to implement a Widget control that exists on every page in the system, which will allow the user to have basic Search & Directory functionality available on each page. This is a tab control defined below, where in the <ul>
the currently selected tab is determined by the the value in Model.CurrentTab
and the corresponding content that I want to display (basically, make visible) is also determined by that value.
<div class="WidgetControl">
<ul class="WidgetTab tabs">
<li <%= (Model.CurrentTab == "Search") ? "class='active'" : "" %>>
<span href='<%= Url.Action("SearchBox", "Search") %>'>Search</span>
</li>
<li <%= (Model.CurrentTab == "Directory") ? "class='active'" : "" %>>
<span href='<%= Url.Action("DirectoryList", "Group") %>'>Directory</span>
</li>
</ul>
<div id="Search" class="tab_container">
<% Html.RenderAction("SearchBox", "Search"
, (Model.CurrentTab == "Search") ? Model.Search : ""); %>
</div>
<div id="Directory" class="tab_container">
<% Html.RenderAction("DirectoryList", "Group"
, (Model.CurrentTab == "Directory") ? Model.Search : ""); %>
</div>
</div>
The reason I want to load both Search
and Directory
is so the page doesn't have to request the content depending on which tab is clicked. I want it all to be available immediately.
The problem I'm having is that if CurrentTab
contains the value "Directory" this means (I assumed) that Html.RenderAction("SearchBox"...
should pass in an empty string. But when it gets to the action method, the View Model passed into SearchBox
contains a value and not ""
I don't understand why this is happening. Even when I pass an empty string into SearchBox
, the View Model still contains a value. Can somebody please explain what's going on? Should I be doing this differently?
update:
public PartialViewResult DirectoryList(DirectoryViewModel vm)
{
return PartialView(vm.Search); // this is expecting a string
}
public PartialViewResult SearchBox(SearchViewModel vm)
{
return PartialView(vm); // the among other things, the Search string is used
}
Both DirectoryViewModel
and SearchViewModel
contain a property called Search