I have a simple code from a book and the code should display data from my controller in the "results" span. What am I missing?
Controller...
public string GetQuote(string symbol)
{
if (symbol.Trim() != "")
return "99";
else
return "Sorry";
}
ASPX...
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<%using (Html.BeginForm("GetQuote","Stocks", new { id = "quoteForm" })) { %>
Symbol:
<%= Html.TextBox("symbol") %>
<input type="submit" />
<span id="results"></span>
<% } %>
<p><i><%=DateTime.Now.ToLongTimeString() %></i></p>
<script type="text/javascript">
$("form[action~='GetQuote']").submit(function() {
$.post($(this).attr("action"), $(this).serialize(), function(response) {
$("#results").html(response);
});
return false;
});
</script>