Re: mvc contrib grid fail

11 views
Skip to first unread message

Eric Hexter

unread,
Dec 10, 2009, 10:07:08 AM12/10/09
to Wagner Miranda, mvccontrib-discuss
Forwarding to the discuss list, for discussion.

On Thu, Dec 10, 2009 at 8:25 AM, Wagner Miranda <wagner....@gmail.com> wrote:
Hi Eric,

sorry for send this mail, but i need a few help.

im using the grid mvc contrib in my project and i find an scenarios that cant solve.

I put in a partialview the grid, that will draw for call of  ajax.beginform updating a div that render a html.renderpartial.
in ajax methos, call a action in controller that set an viewdata used from grid. but the grid in this scenarios dont work.

if i calling the action in controller via common form without ajax, works fine but i need update the infos at a div in my main page.

have you an suggestion?

sorry from my english and thanks.

[]´s
Wagner Benicio

--------------------------------------------------
main page code:
            <% using (Ajax.BeginForm("GetAllCostCenter", "Contract", new AjaxOptions { UpdateTargetId = "atualiza", OnSuccess = "showCostCenters" }))
             { %>
                <input type="submit" value="test" id="tetste" />
            <% } %>
           

my partial view
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="GINModel" %>
<%@ Import Namespace="MvcContrib.UI.Grid.ActionSyntax" %>

    <!-- window search costcenter -->   
    <div id="userDialogAssociateRoles" title="" style="display: none;">
        <% object obj = ViewData["AllCostCenter"];
           if (obj != null)
           {              
        %>
                <% Html.Grid((List<GINModel.CostCenter>)ViewData["AllCostCenter"]).Columns(column =>
                   {
                       column.For(u => u.Codigo);
                       column.For(u => u.Nome);

                   }).Attributes(id => "dataGridCostCenter").Render();
                %>
       <% } %>
     </div>

my method controller:
public ActionResult GetAllCostCenter()
        {
            IList<CostCenter> list = GINBusinessFacade.Instance.SearchAllCostCenter();
            ViewData["AllCostCenter"] = list;
            return View();
        }


Jeremy Skinner

unread,
Dec 10, 2009, 12:06:12 PM12/10/09
to mvccontri...@googlegroups.com
Please could you elaborate on the problem you're having. Are you getting an error?

2009/12/10 Eric Hexter <eric....@gmail.com>

--
Contact Jeffrey Palermo or Eric Hexter with specific questions about the MvcContrib project. Or go to http://mvccontrib.org
 
To unsubscribe from this group, send email to mvccontrib-disc...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/mvccontrib-discuss?hl=en

Wagner Benicio

unread,
Dec 10, 2009, 2:20:35 PM12/10/09
to mvccontrib-discuss
I have an action page, which uses a renderpartial (ascx) where is the
grid.

The viewdata used from this grid is updated out either through form
ajax (ajax.beginform).

The error: the table is not generated by html.grid resulting in
empty table grid, the viewdata having a list of data.
If you call the ascx out of ajax, it works.


On Dec 10, 2:06 pm, Jeremy Skinner <jer...@jeremyskinner.co.uk> wrote:
> Please could you elaborate on the problem you're having. Are you getting an
> error?
>
> 2009/12/10 Eric Hexter <eric.hex...@gmail.com>
>
> > Forwarding to the discuss list, for discussion.
>
> > On Thu, Dec 10, 2009 at 8:25 AM, Wagner Miranda <wagner.mira...@gmail.com>wrote:
>
> >> Hi Eric,
>
> >> sorry for send this mail, but i need a few help.
>
> >> im using the grid mvc contrib in my project and i find an scenarios that
> >> cant solve.
>
> >> I put in a partialview the grid, that will draw for call of
> >> ajax.beginform updating a div that render a html.renderpartial.
> >> in ajax methos, call a action in controller that set an viewdata used from
> >> grid. but the grid in this scenarios dont work.
>
> >> if i calling the action in controller via common form without ajax, works
> >> fine but i need update the infos at a div in my main page.
>
> >> have you an suggestion?
>
> >> sorry from my english and thanks.
>
> >> []´s
> >> Wagner Benicio
>
> >> --------------------------------------------------
> >> main page code:
> >>             <% using (Ajax.BeginForm("GetAllCostCenter", "Contract", new
> >> AjaxOptions { UpdateTargetId = "atualiza", OnSuccess = "showCostCenters" }))
> >>              { %>
> >>                 <input type="submit" value="test" id="tetste" />
> >>             <% } %>
>
> >> my partial view(ascx)
> > MvcContrib project. Or go tohttp://mvccontrib.org

Jeremy Skinner

unread,
Dec 10, 2009, 2:35:20 PM12/10/09
to mvccontri...@googlegroups.com
Works fine for me.

These are the steps I took to create a working example:

controller:

public class TestController : Controller {
   public ActionResult Index() {
      return View();
    }

    //This action will be called by Ajax
   public ActionResult PeopleGrid() {
       var people = new List<Person> {
                new Person() { Name = "Person 1", Id = 1 },
                new Person() { Name = "Person 2", Id = 2 },
                new Person() { Name = "Person 3", Id = 3 },
                new Person() { Name = "Person 4", Id = 4 },
            };

            ViewData["people"] = people;
           
            return View();
    }
}

Partial view - PeopleGrid.ascx


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="MvcContrib.Samples.UI.Models"%>

<%@ Import Namespace="MvcContrib.UI.Grid"%>

<%= Html.Grid<Person>("people").Columns(column => {
        column.For(x => x.Id);
        column.For(x => x.Name);
}) %>

Main view - Index.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript" src="/Scripts/MicrosoftAjax.js"></script>
    <script type="text/javascript" src="/Scripts/MicrosoftMvcAjax.js"></script>
   
   
    <% using (Ajax.BeginForm("PeopleGrid", new AjaxOptions { UpdateTargetId = "grid-placeholder" })) {%>
        <input type="submit" value="Load Grid" />
    <% } %>

    <div id="grid-placeholder"></div>
</asp:Content>

This works as expected.

Jeremy

2009/12/10 Wagner Benicio <wagner....@gmail.com>
Contact Jeffrey Palermo or Eric Hexter with specific questions about the MvcContrib project.  Or go to http://mvccontrib.org
Reply all
Reply to author
Forward
0 new messages