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

[Solved] Grid with PartialView: when sorting just loads the partial view and not the whole page

3 Answers 95 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.
Gee
Top achievements
Rank 1
Gee asked on 26 Mar 2012, 03:14 PM
I have an action that loads the page with the partial view with a grid and works perfectly even with paging but once I tried to sort it via field the whole thing bombs and just loads the partial view and does not include the master page.

Here's the action:

       
public ActionResult Edit(){
return View();
}
[HTTPPOST]
public ActionResult Edit(FormCollection formCollection)
{
return View()
}
public ActionResult Index(string filter1, string filter2, string filter3){
return PartialView(new FilteredItems(Context, filter1, filter2, filter3);
}

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

<%: Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.default.css").Combined(true).Compress(true)) %>
<div class="row">
<% if (Model.Items.Count() == 0) { %>
    No nonprofits match that search filter
<% } else { %>
    <% Html.Telerik().Grid(Model.Items)
           .Name("Companies")
           .Columns(col =>
               {
                   col.Template(item => 
                   col.Bound(item => item.CompanyId).Title("Id");
                   col.Bound(item => item.Name).Title("Name");
                   col.Bound(item => item.Country).Title("Country");
               })
           .Sortable()
           .HtmlAttributes(new { style = "width: 100%" })
           .Footer(false)
           .Render();
    %>
</div>

<%@ Page Title="Select Company" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Select Nonprofit
 
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 
    <div>
        <% using (Ajax.BeginForm("Index", new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "Companies" }))
           { %>
            <div>filter1</div>
                <%: Html.TextBox("filter1", "", new { size=40 }) %>
            <div>filter2</div>
                <%: Html.TextBox("filter2", "", new { size = 40 }) %>
            <div>filter3</div>
                <%: Html.TextBox("filter3", "", new { size = 40 }) %>
             
    <div id="CompanyList" style="padding: 10px 0 0 0px;">
        <% Html.RenderAction("Index"); %>
    </div>
</asp:Content>

3 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 27 Mar 2012, 01:15 PM
Hi,
I don't really understood what you try to do but if you use PartialView for the main controller (Index) then i think you want to use ajax binding.

If not, try to change this 
return PartialView(new FilteredItems(Context, filter1, filter2, filter3); 

by that
return View(new FilteredItems(Context, filter1, filter2, filter3); 


Edit :
I don't see any reference to you masterpage in your view...this is a "control view" and so you need another view that include your control :
For example
Index.aspx including GridControl.ascx

so you controller should be 
return View(new FilteredItems(Context, filter1, filter2, filter3); 

0
Gee
Top achievements
Rank 1
answered on 27 Mar 2012, 02:17 PM
Yeah, had some typo on that PartialView part. I updated the code to show the aspx that is connected to a master page. It's for the edit and the edit calls the ascx page "Index" which generates the Telerik.
0
Dadv
Top achievements
Rank 1
answered on 28 Mar 2012, 09:50 AM
Ouch... hard to understand, too much Typo.

Where is the submit button (or link) for the filter?
Where is the closing '}' for the using Ajax.BeginForm ?

Why using the Grid name (id) for the target?  UpdateTargetId = "Companies" 

Well as is, i can't help you.

Please provide a sample project.

Regards,
Tags
Grid
Asked by
Gee
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Gee
Top achievements
Rank 1
Share this question
or