views:

512

answers:

4

I am doing something wrong and I can not figure out where...

I have this in my view - CreateForm.aspx

<%@ Page Title="" Language="C#"  Inherits="System.Web.Mvc.ViewPage" %>

      <%= this.Ajax.ActionLink("Create New", "CreateForm", new { nr=ViewData["Nr"]??0 }, new AjaxOptions { UpdateTargetId = "panel" + (String.IsNullOrEmpty((string)ViewData["Nr"]) ? "0" : "1") }, new { id = "panel" + (String.IsNullOrEmpty((string)ViewData["Nr"]) ? "0" : "1") + "Form" })%>

    <div id="panel<%=String.IsNullOrEmpty((string)ViewData["Nr"])?"0":"1"%>"></div>

I have this in my controller -

        public ActionResult CreateForm(int nr)
        {
            ViewData["Nr"] = (nr++).ToString();
            return PartialView();
        }

when I click on the Link I expect that the response to be loaded in my panel# (panel0,panel1...) but I am redirected to an empty page with only the returned content

this is the generated html

<a href="/Member.aspx/CreateForm?nr=0" id="panel0Form" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'panel0' });">Create New</a>

    <div id="panel0"></div>

and after click the page view source looks like this

 <a href="/Member.aspx/CreateForm?nr=0" id="panel1Form" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: 'panel1' });">Create New</a>

    <div id="panel1"></div>

I have included Ajax js

    <script src="/content/Microsoft/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>

but I expected this to go into panel0... what am I doing wrong?

P.S.

Debuging with vs.net in MicrosoftMvcAjax.debug.js i get an error

around line 3063...

 var e = Function._validateParams(arguments, [
        {name: "id", type: String},
        {name: "element", mayBeNull: true, domElement: true, optional: true}
    ]);
    if (e) throw e; <-here it trows an error
A: 

Did you remember to include the necessary javascript files before calling AjaxLink?

You need to reference MicrosoftAjax.js and MicrosoftMvcAjax.js for this to work correctly.

Matt Hidinger
yes I Include them in my Site.Master
bogdanbrudiu
+1  A: 

I have figured out my problem... it seams that the version of MicrosoftMvcAjax.js I was using was not up to date.... If you have similar problems as I had get latest version of mvccontrib...

bogdanbrudiu
A: 

Help!!!

I get the same problem. I use MVC 2 beta and the new js file.

Many thanks!

Laurel.Wu
Found a nicer fix:http://forums.asp.net/p/1331418/2671647.aspx<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" /><script src="<%= Url.Content("~/Content/MicrosoftAjax.debug.js") %>" type="text/javascript"></script><script src="<%= Url.Content("~/Content/MicrosoftMvcAjax.debug.js") %>" type="text/javascript"></script>
Laurel.Wu
A: 

I have some experience with this kind of problem. It seems like we must use script file in a correct order to make it work. More specific, you should include MicrosoftAjax before MicrosoftMvcAjax script. Hope it helps

Xuan Chien