Ajax Nerd dinner error for calling registration method

I am new to MVC and I am using the Nerd Dinner MVC sample application in MS MVC2. I am at step 10, "Ajax allows RSVPs to accept." I added a new RSVP controller and added the Register action method like this:

public class RSVPController : Controller
{
    DinnerRepository dinnerRepository = new DinnerRepository();

    //
    // AJAX: /Dinners/RSVPForEvent/1

    [Authorize, AcceptVerbs(HttpVerbs.Post)]
    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!");
    }
}

I added links to the Ajax script libraries and added the code below to the Details view, as described in the article:

<div id="rsvpmsg">

<% if(Request.IsAuthenticated) { %>

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

        <p>You are registred 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>

When I click on the “RSVP for this event” link, I get a 404 message saying that the resource was not found:

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: /NerdDinner/RSVP/Register/24

Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4205

, Register. "AcceptVerbs (HttpVerbs.Post)" Register, . , " - " . html , , Ajax - ? Nerd Dinner? , MVC1, MVC2 - ?

,

+5
8

, ". ":

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

, .

, 404, - actionlink:

 Ajax.ActionLink(...

URL, GET POST, AcceptVerbs(HttpVerbs.Post) . :

using (Ajax.BeginForm("Controller", "Action", new AjaxOptions { UpdateTargetId = "f1" } )) { %>
 <div id="f1">
 <!-- form fields here -->
 <input type="submit" />
 </div>
<% } %>
+1

PDF ( HTML) HTML- script ANSI (0x94), ASCII (0x22). .

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

Visual Studio JavaScript ( " " ), , . type - , .

Chrome, , "" " HTML". type Register, .

+2

, - , MVC 3, , MS AJAX, MVC 3 jQuery, .

+1

, Java/JSF, ,

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

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

-. , .

+1

Details.cshtml, MVC3. GET, POST .

<div id="rsvpmsg">
    @if (Request.IsAuthenticated)
    {
        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", HttpMethod = "Post" })
        }
    }
    else
    {
        <p>
            <a href="/Account/Logon">Logon</a> to RSVP for this event.</p>
    }
</div>
@section JavaScript
{
    <script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>;
    <script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>;
}

, , , , MVC 3 JavaScript.

, 2 : Javascript webconfig:

  <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings> 

false, javascript, Action, javascript, - HTML:

<a onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), 
{ insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'Post', updateTargetId: 'rsvpmsg' });" href="/RSVP/Register/13">RSVP for this event</a>

, . javascript :

<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    @RenderSection("JavaScript",required:false)
</head>

javascript HTML:

RSVP

, " " MVC 3.

+1

http- Ajax.ActionLink, , . new AjaxOptions { UpdateTargetId="rsvpmsg",HttpMethod="POST"}

0

site.master,

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

MVC3/Razor, . 24 ... . , .

javascript web.config "" , , "true" . , , - ( , , ).

tid- wrox. RSVPStatus.cshtml:

<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>

Everything works as intended. I know that Zack mentioned this line of code above (and a bunch of other things that lead me in the right direction), but I used a partial view and did not see the head tag since I started messing around with MVC. I know this, probably somewhere, but all the smoke and mirrors of what MS is programming now make it difficult to cut it, and I probably would go down the path of Zach at some point. So +1 for him.

In any case, I hope that this will help someone save the day.

0
source

All Articles