Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 2
This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 17th, 2010, 02:49 PM
Registered User
 
Join Date: Dec 2010
Posts: 8
Thanks: 6
Thanked 2 Times in 2 Posts
Default Calling the "Regsiter" action method using AJAX (page 122)

Hello all,
For some reason, this piece of code does not work at least with me. Here is the code..
--
<%:Ajax.ActionLink("RSVP for this event", "Register","RSVP", new { id=Model.DinnerID }, new AjaxOptions { UpdateTargetId="rsvpmsg"})%>
--

Here is the error that I got: Microsoft JScript runtime error: 'Sys' is undefined.

and the dynamic code shown is ": <a href="/RSVP/Register/9" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'rsvpmsg' });">RSVP for this event</a>

Do you guys have any idea why this mess happen?

~L.G
Reply With Quote
  #2 (permalink)  
Old December 17th, 2010, 03:11 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Compare your code with this:

Code:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>    

<script type="text/javascript">

    function AnimateRSVPMessage() {
        $("#rsvpmsg").animate({ fontSize: "1.5em" }, 400);
    }

</script>
    
<div id="rsvpmsg">

<% if (Request.IsAuthenticated) { %>

    <% if (Model.IsHostedBy(Context.User.Identity.Name)) { %>

        <p>You are the host for this event!</p>

    <% } else if (Model.IsUserRegistered(Context.User.Identity.Name)) { %>        
    
        <p>You are registered for this event!</p>
    
    <% }
       else
       { %>  
    
        <%: Ajax.ActionLink("RSVP for this event",
                             "Register", "RSVP",
                             new { id = Model.DinnerID },
                             new AjaxOptions { UpdateTargetId = "rsvpmsg", OnSuccess = "AnimateRSVPMessage" })%>         
    <% } %>
    
<% } %>
    
</div>
Reply With Quote
  #3 (permalink)  
Old December 17th, 2010, 03:24 PM
Registered User
 
Join Date: Dec 2010
Posts: 8
Thanks: 6
Thanked 2 Times in 2 Posts
Default Calling "Register" method using AJAX (page 122)

flyinhawaiian,

The only difference that I see from your code is the "AnimateRSVPMessage()" function that you added the code and passed it to the new Ajaxoptions as a parameter.

I don't think that adding that extra function will solve the error that I have gotten. Any other options ?

Thank you!

L.G
Reply With Quote
The Following User Says Thank You to lagonave For This Useful Post:
saymamohib28 (April 7th, 2011)
  #4 (permalink)  
Old December 17th, 2010, 04:12 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Check Web.config see if you have:

[code]
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
[\code]
Reply With Quote
  #5 (permalink)  
Old December 17th, 2010, 04:15 PM
Registered User
 
Join Date: Dec 2010
Posts: 8
Thanks: 6
Thanked 2 Times in 2 Posts
Default Calling the "Register" method using AJAX

flyinhawaiian,

I just saw that the code that you have posted is the next step on that tutorial on page 124. I'm still trying to get page 122-123 to work according to the book. Something is missing and I can't put my hands on it yet.

Here is my complete code for the "Detail.aspx":

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NerdDinner.Model s.Dinner>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
Details
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2><%: Model.Title %></h2>
<p>
<strong>When:</strong>
<%: Model.EventDate.ToShortDateString() %>
<strong>@</strong>
<%: Model.EventDate.ToShortTimeString() %>
</p>
<p>
<strong>Where:</strong>
<%: Model.Address %>,
<%: Model.Country %>
</p>
<p>
<strong>Description:</strong>
<%: Model.Description %>
</p>
<p>
<strong>Organizer:</strong>
<%: Model.HostedBy %> (<%: Model.ContactPhone %>)
</p>

<div id="rsvpmsg">
<% if(Request.IsAuthenticated){ %>

<% if(Model.IsUserRegistered(Context.User.Identity.Na me)) { %>
<p>You are registered for this event!</p>

<% } else { %>

<%:Ajax.ActionLink("RSVP for this event (SecondTest)", "Register","RSVP", new { id=Model.DinnerID }, new AjaxOptions { UpdateTargetId="rsvpmsg"}) %>

<% } %>

<%} else { %>
<%: Html.ActionLink("Logon to RSVP for this event.", "LogOn", "Account") %>
<% } %>
</div>

<% if (Model.IsHostedBy(Context.User.Identity.Name)) { %>
<%: Html.ActionLink("Edit Dinner", "Edit", new { id = Model.DinnerID })%> |
<%: Html.ActionLink("Delete Dinner", "Delete", new { id = Model.DinnerID })%>
<%} %>

</asp:Content>
Reply With Quote
The Following User Says Thank You to lagonave For This Useful Post:
saymamohib26 (April 7th, 2011)
  #6 (permalink)  
Old December 17th, 2010, 04:31 PM
Registered User
 
Join Date: Dec 2010
Posts: 8
Thanks: 6
Thanked 2 Times in 2 Posts
Default

Yes, I checked the web.config file and it has everything except for the "
Code:
 ...
part.
Reply With Quote
  #7 (permalink)  
Old December 17th, 2010, 04:39 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Ok one more thing to check. In my notes I put reference to ajax script in Site.Master (this is not in the book).

Try putting this between the <body> </bod> tags.
[code]
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
[\code\
Reply With Quote
The Following User Says Thank You to flyinhawaiian For This Useful Post:
lagonave (December 17th, 2010)
  #8 (permalink)  
Old December 17th, 2010, 04:45 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Also, scripts are cached. May need to clear cache in IE (Ctrl+F5). I use fiddler to clear my cache. http://www.fiddler2.com/fiddler2/
Reply With Quote
The Following User Says Thank You to flyinhawaiian For This Useful Post:
lagonave (December 17th, 2010)
  #9 (permalink)  
Old December 17th, 2010, 04:56 PM
Registered User
 
Join Date: Dec 2010
Posts: 8
Thanks: 6
Thanked 2 Times in 2 Posts
Default Calling the "Register" method using AJAX

flyinhawaiian,
It works! I have removed the " <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>


and placed them in the Site.Master as suggested. Now it works like a champ. Thank you sir for your help. I appreciate it.

~L. G.
Reply With Quote
  #10 (permalink)  
Old December 17th, 2010, 05:08 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts
Default

Two heads are better than one. I knew we could both figure this out. I find that I learn more by helping others. Merry Christmas. :)
Reply With Quote
The Following User Says Thank You to flyinhawaiian For This Useful Post:
lagonave (December 17th, 2010)
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MSXSL gives error message for "for" inside "select" ilyaz XSLT 1 December 9th, 2010 04:02 PM
Difficulties with "web.config" and "ASPNETDB" CFRham BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 2 July 3rd, 2010 10:19 AM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM



All times are GMT -4. The time now is 03:28 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.