Partial View

If you want to reuse a view in your web application, you can go for the partial view concept. Partial view is like a regular view with a file extension .cshtml. We can use partial views in a situation where we need a header, footer reused for an MVC web application. We can say that it’s like a user control concept in ASP.NET.

Steps for Creating Application:
1) Click New Project, then select Visual C# on the left, then Web and then select ASP.NET  Web Application. Name your project and then click OK.

2) Click Views,  right click Shared , now Add and click View.


3) Now Give it name, I am giving it name WeatherForecast.
See Snapshot:


4) Go to http://www.accuweather.com/en/free-weather-widgets/current
5) Select your preference like small widgets, location selection etc.
6) At bottom of page read terms and condition and if you are agree put check on box and click Grab the code.
7) Copy the code.
See Snapshot:


8) Go back to widget partial view Weather and paste the code we just copied
9) Go to file (top left of screen) and click Save
10) Go to views --> shared click _Layout.cshtml
11) Just before @RenderBody() add  @Html.Partial("your partial view name") since I created partial view with name WeatherForecast I will add  @Html.Partial("WeatherForecast")
12) Run the application to see how it works.

We Are Done!
Thank You!





















Post a Comment

Previous Post Next Post