Skip to content

Instantly share code, notes, and snippets.

@rodolfofadino
Created August 15, 2013 02:20
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 rodolfofadino/6237668 to your computer and use it in GitHub Desktop.
Save rodolfofadino/6237668 to your computer and use it in GitHub Desktop.
Exemplo ActionResult JavaScript (MVC2,3,4,5)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
public JavaScriptResult RetornaJs()
{
string script = "alert('olá');";
return JavaScript(script);
}
}
}
//index.aspx
//<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
//<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
// Home Page
//</asp:Content>
//<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
// <h2><%: ViewData["Message"] %></h2>
// <p>
// To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
// </p>
// <script type="text/javascript" src="/Home/RetornaJS"></script>
//</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment