MVC partial view (partial views)

Source: Internet
Author: User

A partial view, which is part of the overall view. A single view page is displayed above the overall page, using the steps below

1. Creating View data is ViewModel

 Public class Footerviewmodel    {        publicstringgetset;}          Public string Get Set ; }    }

2. Create a partial view. New View--Select a partial view and write the following code for the partial view: (Strongly typed view)

@using Mymvc3demo.viewmodels@model Footerviewmodel            <div style="text-align:right;background-color:silver;color:darkcyan;border:1px solid gray; margin-top:2px;padding-right:10px; ">    @Model. Companyname© @Model.year </div>

3. View page reference

@{                html.renderpartial ("Footer", Model.footerdata);            }

Of course the page can

@Html. Partial ("Footer", Model.footerdata)

The difference between 1>, renderpartial, and partial is that Html.renderpartial writes the results of the partial view directly to the HTTP response stream, and html.partial returns the Mvchtmlstring value. In other words, the renderpartial has no return value, the output is written directly in the HTTP corresponding stream, while the partial has a return value, the returned string is written directly on the page, and finally output to the HTPP response stream.

2>html.renderaction (""), the method is a page call method, the page through renderaction the request to action, let the action output after the result is written to the HTPP response stream.

Html.renderaction ("Getaddnewlink");

MVC partial view (partial views)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.