Asp.net-mvc – How to pass a string to a partial view in ASP.NET MVC

asp.net-mvc

I have a search page that if there is results in the list it passes this list to a view.
However if there are no results I want to send the searched text to a no results found view.
How would I go about this?

Best Solution

You will need to have the searched text available as part of the model that is returned to the view. Then you have two options -

Using the RenderPartial will pass the returned view to the partial view so you can access the value you want from there.

Html.RenderPartial("PartialView");

Alternatively, you can pass the string as the model for the partial view using

Html.RenderPartial("PartialView", Model.SearchedText);

Which might make sense if you want to use the no results partial view with different models.