"ASP. NET MVC Learning Notes"-child Action

Source: Internet
Author: User

This article references:http://www.cnblogs.com/willick/p/3410855.html

1. Child action is similar to Patial view and can be reused for the same sub-content in different parts of the application. The difference is that it renders the child content by invoking the action method in the controller, and typically contains the processing of the business. Any action can act as a child action. Example:

 //  1, childactiononly features ensure that the action Can only be called as a child action (not required)  [childactiononly]   Public   ActionResult time () { return   Partialview (DateTime.Now);}  //  2, View time.cshtml   @model DateTime  <p>the time is : @ Model.toshorttimestring () </p> //  3, in Add the following code to the List.cshtml view to invoke the time action method:  @Html. Action ( " time  " ) 

The time action method is called by the @Html. Action method to render the child content. In this method we only pass an action name parameter, and MVC will find the action based on the current view's controller. If you are invoking the action method in another controller, you need to specify the controller's name in the second parameter, as follows:

@Html. Action ("time""mycontroller")

The method can also pass values to the parameters of the action method, such as the action with the following parameters:

 Public actionresult Time (DateTime time) {     return  Partialview (time);} @Html. Action ("time"new {time = DateTime.Now})

"ASP. NET MVC Learning Notes"-child Action

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.