I have a search function on my site, and one of the options the user has is to select the type of search.
So given this example in a view:
@using System.Data
@model DataSet
hello, world
<br />
@ViewData["searchtype"]
@if (ViewData["searchtype"] == "rank")
{
<h2>Ranks</h2>
<ol>
@foreach (DataRow dr in Model.Tables[0].Rows)
{
<li>@dr["name"].ToString()</li>
}
</ol>
}
I would expect it to either give me the header Ranks by itself (if the datatable is empty) or a numbered list of ranks following that header.
What I get instead is this:
hello, world
rank
So I know that it's getting to the view. And I know that it's able to see the value of the ViewData["searchtype"]
. But the conditional, which should be evaluated as true, is not.
And I know that the obvious answer is for ViewData["searchtype"]
to be changed to ViewData["searchtype"].ToString()
, but when I do that, I get literally nothing. No "hello, world", no "rank", no "Rank", and nothing from the _Layout page, either. Just a pristine blank browser.
Also, I'm aware that using a DataSet as a model instead of an object is not optimal, but the data tables generated differ depending on the search type, so I'm stuck with that.