Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subdigital/170591 to your computer and use it in GitHub Desktop.
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
//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