Click here to Skip to main content
15,886,362 members
Articles / Web Development / ASP.NET

Partial Rendering Control using JQuery in MVC 2

Rate me:
Please Sign up or sign in to vote.
4.17/5 (8 votes)
13 Jun 2010CPOL5 min read 46.7K   24  
This article shows a web custom control that allows partial rendering using JQuery in an MVC 2 web application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using JqueryController;
using JqueryControlMVC.Models;

namespace JqueryControlMVC.Controllers
{
    [HandleError]
    public class HomeController : MvcControllerBase
    {
        private const string UserControlPath="~/Views/UserControl/ViewUserControl1.ascx";
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";            
            return View();
            
        }
        [HttpPost]
        public ActionResult Index(string x)
        {
            
            if (this.IsPartialRendering && this.PostParameter.ContainsKey("action"))
            {
                switch (this.PostParameter["action"])
                { 
                    case "refreshTime":
                        TimeModel t = new TimeModel();
                        return this.RefreshJQueryPanel<TimeModel>("JqueryController1", UserControlPath, t,"CallBack","parameterToBeReturned" );
                        break;
                 //any other action
                }
                
            }
            return View();
        }

        public ActionResult About()
        {
            return View();
            
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect PeluSoft Limited
United Kingdom United Kingdom
I have been fascinated by software development since I was 10 years old. I'm proud of learned the first programming language with an Olivetti PC 128S based on Microsoft BASIC. I'm a Software Architect/Senior Developer with a strong background of all the developing Microsoft's technologies.

Comments and Discussions