Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a string to a partial view in ASP.NET MVC?

Tags:

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?

like image 976
ddd Avatar asked Dec 17 '22 07:12

ddd


1 Answers

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.

like image 144
Martynnw Avatar answered Jan 18 '23 01:01

Martynnw