Created
August 19, 2009 19:07
-
-
Save subdigital/170591 to your computer and use it in GitHub Desktop.
showing how to do a quick & dirty javascript template sort of like rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HomeController | |
public ActionResult Foo() | |
{ | |
if(Request.IsAjaxRequest()) | |
{ | |
return View("_foo"); | |
} | |
return View(); | |
} | |
//_foo.ascx | |
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> | |
<script type="text/javascript"> | |
$("#container").css({ border: "solid 4px red" }); | |
$("#container").animate({ width: 300, height: 50 }); | |
</script> | |
//on the client side: (Index.aspx) | |
%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> | |
<asp:Content ID="indexHead" ContentPlaceHolderID="head" runat="server"> | |
<title>Home Page</title> | |
<script type="text/javascript"> | |
function doit() { | |
$.get("/home/foo", null, function(result) { | |
$("#container").html(result); | |
}) | |
} | |
</script> | |
</asp:Content> | |
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"> | |
<input type="button" onclick="doit()" value="Do it!" /> | |
<div id="container" /> | |
</asp:Content> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment