p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET MVC 2 (http://p2p.wrox.com/forumdisplay.php?f=588)
-   -   Calling the "Regsiter" action method using AJAX (page 122) (http://p2p.wrox.com/showthread.php?t=81952)

caof2005 February 27th, 2011 05:11 AM

Ajax Scripts also works inside <head></head> tags!
 
Quote:

Originally Posted by flyinhawaiian (Post 266691)
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\

It also works if you put the previous 2 script references within the <head> and </head> tags inside the Site.Master file!!! :)

BrennanFuchs April 6th, 2011 08:40 PM

Still need help with this one!
 
Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /RSVP/Register/9


----------------------
-I've moved the Ajax.js script references to site.master as suggested
-checked config for required namespaces
-Not sure what's missing here as even error occurs before it even hops into the RSVPController. Well not totally true it creates the dinnerRepository
Code:

DinnerRepository dinnerRepository = new DinnerRepository();
and then doesn't seem to recognize the Register function.
-I've also out of curiosity removed the HttpPost it THEN recognized the function but returned the content just to it's own page as opposed to the Details page within the rsvpmsg div...


--------------------------------
Code:

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NerdDinner.Models;

namespace NerdDinner.Controllers
{
    public class RSVPController : Controller
    {

        DinnerRepository dinnerRepository = new DinnerRepository();

        //
        // AJAX: /Dinners/Register/1

        [Authorize, HttpPost]
        public ActionResult Register(int id)
        {

            Dinner dinner = dinnerRepository.GetDinner(id);

            if (!dinner.IsUserRegistered(User.Identity.Name))
            {
                RSVP rsvp = new RSVP();
                rsvp.AttendeeName = User.Identity.Name;

                dinner.RSVPs.Add(rsvp);
                dinnerRepository.Save();
            }

            return Content("Thanks - we'll see you there!");
        }
    }
}


----------------------

Code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NerdDinner.Models.Dinner>" %>
 

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Dinner: <%: Model.Title %>
</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(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" })%>
       
        <% } %>
    <% }
      else
      { %>
            <a href="/Account/Logon">Logon</a> to RSVP for this event.
    <% } %>
    </div>

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

</asp:Content>


saymamohib26 April 7th, 2011 03:31 AM

PS3 Hacks
 
I wrote a review of
PS3 Hacks
xbox hacks
psp hacks

saymamohib28 April 7th, 2011 03:32 AM

I wrote a review of about>>>>>>>
erp definiton
erp definiton

flyinhawaiian April 7th, 2011 10:25 AM

BrennanFuchs, when you got the "Server Error in '/' Application." message were you logged in (as a nerd dinner user)? Are you hitting that URL through the javacript or did you manually type that URL in the browser?

BrennanFuchs April 7th, 2011 07:35 PM

yes am logged in as user. One not registered to that dinner of course.
I'm simply clicking the 'RSVP to this event' Ajax.Action link URL on the Details page. So not manually typing.

Thanks so much for the help.. this transition is not a smooth one for this dinosaur..

BrennanFuchs April 14th, 2011 07:30 PM

Issue persists
 
Whats strange is it I can get it to work but just returning the
return Content("Thanks - we'll see you there!");

text to a blank screen if i remove the HttpPost

[Authorize]

as opposed to
[Authorize, HttpPost]

naturally this is not bringing me back to the view but just to a blank screen with this text.

bahusoid April 15th, 2011 11:50 AM

Seems like you are using unobtrusive java script (check in your web.config: <add key="UnobtrusiveJavaScriptEnabled" value="true" />). To fix it add to your View following script:
Code:

<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
Probably you should also specify HttpMethod explicitly:
Code:

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


flyinhawaiian April 15th, 2011 12:29 PM

Still not sure what is causing your problem. I don't recall anyone else having same problem. I would suggest reviewing all steps from the book to see if you missed something somewhere (get lastest .net mvc, all windows updates, security updates, etc.)

Any chance you can post your code in a public place? Then I can at least try to reproduce the problem on my machine and compare code.

BrennanFuchs April 19th, 2011 07:54 PM

Still no luck
 
Thanks bahusoid tried you'r suggestion you were correct about the config key entry (unobtrusive) and I've tried adding the script reference and the explicit casting with no change in behavior.

Something to note: i ONLY get this error when i add the HttpPost qualifier to my 'Register' method in the RSVP Controller. [Authorize, HttpPost]

EVEN with the explicit setting of the httppost as suggest by bahusoid in the actionlink if i remove the qualifier it will save the RSVP but not redirect to the div/ajax action control just to a blank screen with the content string. As SOON as I put that HttpPost back [Authorize, HttpPost] it immediately fails out when trying to hop into the Register method.

Without the post it hops in fine and does the save i just dont post back to the detail page but to RSVP/Register/[id] empty screen...

Flyinhawaiian: I've pulled and recopied every code snippet just to be sure :S. I had MVC3 installed before I even started this book. I appreciate all the effort guys, finally have the work comp setup to a degree when i have the time ill be dragging this in to have a second and 3rd set of eyes on this as well.

As for posting it to a public place i could email you my project? if you want to hit me up kweejibow@hotmail.com

Thanks
Brennan


All times are GMT -4. The time now is 10:10 AM.

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