Hi I have an MVC textbox I’m populating like:
<p>Find: @Html.TextBox("SearchString", Request.Cookies["query"].Value as string, new { id = "search" })
<input type="submit" value="Search" class="button" />
</p>
This works as I wanted but the problem is if the user clears their cookies there will be a null exception obviously.
How are you supposed to set it up so that if the cookie is null then it doesn’t even try to put anything in the textbox?
Could you could use a ternary operator
The best solution would be to get the cookie in the controller and then pass it through using the viewBag or adding it to a ViewModel.