Rendering a Child Action

You can invoke a child action using the Html.Action helper. With this helper, the action method is
executed, the ViewResult is processed, and the output is injected into the response to the client.

Below is the example that explain how you can implement child Action

 using System;  
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace child_Action.Controllers
{
public class ChildActionController : Controller
{
//
// GET: /ChildAction/
public ActionResult Index()
{
return View();
}
public ActionResult ChildActionDemo()
{
return View();
}
[ChildActionOnly]
public ActionResult Time()
{
return PartialView(DateTime.Now);
}
}
}
--------------------------------------------------------------------------------------------------------------
View -> ChildAction->ChildActionDemo
@{
ViewBag.Title = "Child Action Demonstration";
}

This is the method rendered by the action method


@Html.Action("Time")

This is the method rendered by the action method again


--------------------------------------------------------------------------------------------------------------
Partial View: Shared->Time
@model DateTime

The time is: @Model.ToShortTimeString()


Published by Nirbhay

Technology Geek,Blogger,Reviewer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: