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