views:

38

answers:

1

ViewData.Model.ExecuteResult does not exist in ASP.NET MVC2, but in MVC1.

What is the alternative in ASP.NET MVC2?

What I want to do, is to update a table after an ajax request. So I put the table in an extra View. How can I update this partial view without loading the whole page again?

+1  A: 

ExecuteResult is a method on the System.Web.Mvc.ActionResult class. Are you sure you don't mean to be looking there?

http://aspnet.codeplex.com/SourceControl/changeset/view/23011#266522

The Model property is just an object type, and always has been, AFAIK.

As for updating the table, what I've done in the past, to update a portion of a page after a partial view is to use Ajax.BeginForm like so:

<% using (Ajax.BeginForm("Customers", new AjaxOptions { UpdateTargetId  = "customerList"})) { %>
    <!-- FORM HERE -->
<% } %>
<div id="customerList">
    <% Html.RenderPartial("CustomerList"); %>
</div>

'UpdateTargetId' is the key here, and tells MVC to use the result of the "Customers" action to replace (by default, you can append by setting the InsertionMode AjaxOption to InsertBefore or InsertAfter) everything inside the element withthe Id you specify.

If you want to use the same action to service the full page request and the Ajax request, you can use the IsAjaxRequest extension method to determine what to return:

if (Request.IsAjaxRequest())
    return PartialView("CustomerList");

// Not an Ajax request, return the full view
return View();

Hope that helps!

Brandon Satrom
in ASP.NET MVC in Action there is this expression mentioned
Rookian
do you know the page #?
Brandon Satrom
page number 78<% ViewData.Model.ExecuteResult(ViewContext); %>
Rookian
Ah, so in this case the authors are using the ViewResult to illustrate how PartialViews relate to Views. In the example of page 78, a ViewResult has been passed into the view. ViewResult is an ActionResult type, and thus, has an ExecuteResult method. That's just part of the example though, and not an inherent property of the Model object on the ViewDataDictionary. As I said above, Model is just object, so it will have whatever methods and properties that the object assigned to it have.
Brandon Satrom