>

Articles → ASP .NET MVC → Passing parameter in partial views in asp.net mvc

Passing parameter in partial views in asp.net mvc






Sample project




Picture showing the project structure of the sample MVC application

Click to Enlarge


Adding partial view




Picture showing adding the partial view inside the Home folder

Click to Enlarge



@Html.Partial("_PartialView")



Passing parameters in partial view






@{
ViewBag.Title = "Home Page";
string option = "search";
}
@Html.Partial("_PartialView", option)




<table>
@if (@Model  == "search")
{
<tr>
   <td><a href="http://google.com" target="_blank">Google</a></td>
</tr>
<tr>
   <td><a href="http://bing.com" target="_blank">Bing</a></td>
</tr>
}
else
{
<tr>
   <td><a href="mail.yahoo.com" target="_blank">Yahoo mail</a></td>
</tr>
}
</table>




Picture showing the output of partial views in MVC application

Click to Enlarge



Picture showing the output of partial views in MVC application

Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Friday, October 16, 2015

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250