views:

16

answers:

2

I can see the result when entering anything in text field. The result does go to the DIV I want. However, I look at the source code for the page, I don't see the replacement element.

For example, I enter 'aaaaaaaaaaaaaaaa', click submit button, I see the result as You entered aaaaaaaaaaaaaaaa; But right click to open source, I don't see its html element

Because I use Accordion in other place, Accordion doesn't work well because JavaScript doesn't see the html elements returned from Action.

What shall I do to fix it?

The View

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<h2>Home Page</h2>
<%using (Ajax.BeginForm("Index", new AjaxOptions { UpdateTargetId = "HomeResult", InsertionMode = InsertionMode.Replace }))
  { %>
    <%= Html.TextBox("query", null, new {size=40}) %>
    <input type="submit" value="Home Submit" />
<%} %>

<div id="HomeResult"> 
    <h2>Home result goes here.</h2>
    <%Html.RenderPartial("PartialResult", ViewData.Model); %>
</div>

The Controller Action

    public ActionResult Index()
    {            
        if (Request.IsAjaxRequest())
        {
            ViewData["Message"] = "Partial View Logon";

            return PartialView("PartialResult", Request.Params.Get("query"));
        }
        return View();
    }

The Partial Result View

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<div>
<% if (Model != null) %>
<% { %>
    <h1>
        You entered <%= Model.ToString() %>
    </h1>
<% } %>
</div>
A: 

I think you are looking down the wrong path with your issue. You are viewing the source for the loaded DOM, not the updated DOM. I say use Firefox/Chrome and the web developer toolbar, which allows you to view "generated" source.

Dustin Laine
I saw the html element in Firebug, thanks for reminding me.
Qi Shu
A: 

right click to open source

will give you the page source when the page was downloaded, and not reflect changes made to the DOM since page load. Perhaps you should consider using a proper web debugger such as FireBug.

Once you can see what's really going on, you might better be able to figure out where things are going wrong.

spender
Thanks. I add RunAccordion jquery javascript function and call it in Ajax OnSuccess event. It works.
Qi Shu