Created
August 15, 2013 02:20
-
-
Save rodolfofadino/6237668 to your computer and use it in GitHub Desktop.
Exemplo ActionResult JavaScript (MVC2,3,4,5)
This file contains hidden or 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
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