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

Passing parameter in partial views in asp.net mvc






Sample project





Click to Enlarge


Adding partial view





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>





Click to Enlarge




Click to Enlarge




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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250