This is a migrated thread and some comments may be shown as answers.

[Solved] Grid Client Selection DataBinding(404)

5 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hatsuki
Top achievements
Rank 1
Hatsuki asked on 03 Apr 2012, 10:15 AM
Hi, I am new to Telerik. I was following the MVC Client Selection tutorial and getting struggle with Databinding. 
Here is the code in view
<%=Html.Telerik().Grid((IEnumerable<ProductVariants>)ViewData["ProductVariants"])
 .Name("ProductVariantsGrid")
 .Columns(columns => 
 {
     columns.Bound(o => o.Code);
     columns.Bound(o => o.Size);
     columns.Bound(o => o.Name);
     columns.Bound(o => o.Price);
     columns.Bound(o => o.BuyCurrency);
     columns.Bound(o => o.Sell);
}).DataBinding(dataBinding => dataBinding.Ajax().Select("_SelectionClientSide_ProductVariants", "Grid"))
 .Pageable()
 .Sortable()
 .Selectable()
 .ClientEvents(events=>events.OnRowSelect("onRowSelected"))
Here is code in Controller
[GridAction]
public ActionResult _SelectionClientSide_ProductVariants() 
{
    return View(new GridModel<ProductVariants> {
        Data = _SMBoomDevRepository.FindAllProductVariants()
    });
}

When the DataBinding was appended, all the page and column click would be disabled---HTML 404.
I feel like something was wrong in Controller Code.
Can you help me to spot the error?
Thank you very much.
 

5 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 04 Apr 2012, 02:40 PM
Hi,
Can you give us a sample project?
0
Hatsuki
Top achievements
Rank 1
answered on 04 Apr 2012, 10:44 PM
Hi Dadv,
Thanks for you response.
Here is the sample project.
When the page or the column is clicked, the 404 alert will be popuped.
I am not quite sure, but I guess the problem is in 
.DataBinding(dataBinding => dataBinding.Ajax().Select("_SelectionClientSide_ProductVariants", "Grid"))
[GridAction]
public ActionResult _SelectionClientSide_ProductVariants() 
{
    return View(new GridModel<ProductVariants> {
        Data = _SMBoomDevRepository.FindAllProductVariants()
    });
}
Thanks for your help. 
0
Accepted
Dadv
Top achievements
Rank 1
answered on 05 Apr 2012, 11:05 AM
Easy fix :

        <% Html.Telerik().Grid<ProductVariants>()
        .Name("ProductVariantsGrid")
        .Columns(columns =>
        {
            columns.Bound(o => o.Product);
            columns.Bound(o => o.Code);
            columns.Bound(o => o.Size);
            columns.Bound(o => o.Name);
            columns.Bound(o => o.Price);
            columns.Bound(o => o.BuyCurrency);
            columns.Bound(o => o.Sell);
            columns.Bound(o => o.SellCurrency);
            columns.Bound(o => o.Active);
            columns.Bound(o => o.Description);
            columns.Bound(o => o.Model);
            columns.Bound(o => o.Weight);
            columns.Bound(o => o.Brand);
            columns.Bound(o => o.SupplierName).Hidden();


        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_SelectionClientSide_ProductVariants", "Home"))
        .Pageable()
        .Sortable()
        .Selectable()
        .ClientEvents(events=>events.OnRowSelect("onRowSelected"))
        .RowAction(row => row.Selected = row.DataItem.Code.Equals(ViewData["ProductCode"])).Render(); 
      %>

 public class HomeController : Controller
    {
        ProductVariants _ProductVariants = new ProductVariants();
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();

        }


        [GridAction]
        public ActionResult _SelectionClientSide_ProductVariants(GridCommand command) 
        {
            return View(new GridModel {
                Data = _ProductVariants.FindAllProductVariants()
            });
        }


        public ActionResult About()
        {
            return View();
        }
    }


 public IQueryable<ProductVariants> FindAllProductVariants() {             
            var list =  new List<ProductVariants>();

            list.Add(new ProductVariants { Product = "Test1" });
            list.Add(new ProductVariants { Product = "Test2" });
            list.Add(new ProductVariants { Product = "Test3" });
            list.Add(new ProductVariants { Product = "Test4" });
            list.Add(new ProductVariants { Product = "Test5" });
            return list.AsQueryable(); }


You should consider to NOT use webform AND mvc in the same page, you could have a lot a strange behavior.
0
Hatsuki
Top achievements
Rank 1
answered on 05 Apr 2012, 12:00 PM
Thanks for you reply. It's really helpful.
I just wonder that it is well-advised to sparate webform from mvc page, because they are put together in this example. http://demos.telerik.com/aspnet-mvc/grid/selectionclientside
 
0
Dadv
Top achievements
Rank 1
answered on 05 Apr 2012, 01:08 PM
Well i'm certainly blind but.. i didn't see any webform part in the sample :)

i was talking of this sort of webform :

<asp:Table ID="tbDetails" runat="server" BorderStyle="None">
                      <asp:TableRow>
                      <asp:TableCell><asp:label ID="lbDescription" runat="server" Text="Description" /></asp:TableCell>
                      <asp:TableCell><asp:TextBox ID="txtDescription" runat="server" /></asp:TableCell>
                      </asp:TableRow>

That need to have a code behind for well working
Tags
Grid
Asked by
Hatsuki
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Hatsuki
Top achievements
Rank 1
Share this question
or