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

[Solved] hoa to change System.Web.Mvc.ViewPage namespace to System.Web.Mvc.ViewPage<Model>

1 Answer 136 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
shanker bangari
Top achievements
Rank 1
shanker bangari asked on 16 Jul 2010, 12:21 PM
Hi,


i doing one application.That is grid binding .i got this error 

System.Web.Mvc.HtmlHelper<object>' does not contain a definition for 'GridView' and the best extension method overload 'MvcApplication2.Code.GridViewExtensions.GridView<T>(System.Web.Mvc.HtmlHelper, MvcApplication2.Code.GridViewData<T>, System.Action<MvcApplication2.Code.GridViewData<T>>, System.Action<T,string>, string, string, System.Action<T>, System.Action<MvcApplication2.Code.GridViewData<T>>)' 


how to find this solution and how to change  System.Web.Mvc.ViewPage to System.Web.Mvc.ViewPage<Model> please give step by step am learning mvc . thanks and regards shanker

<

1 Answer, 1 is accepted

Sort by
0
King Wilder
Top achievements
Rank 2
answered on 19 Jul 2010, 08:10 PM
Your error message seems to have two different issues:
  1. GridView - no definition for the GridView control - you should be using the MVC Grid HtmlHelper
  2. No Model - you aren't passing a ViewModel to the view

It's hard to completely answer your question without knowing a little more, like looking at your controller action for this view.

Best practices say that you should pass a ViewModel of some sort, which is strongly-typed, to the view.  This ViewModel would contain data that is used by the view.

In your controller action, you can have something like:

public ActionResult Index()
{
    HomeViewData viewData = new HomeViewData();
    viewData.CustomerList = CustomerService.GetAll();
    return View(viewData);
}

Here's what the ViewModel (or strongly-typed ViewData) looks like:

public class HomeViewData
{
    public Customer Customer { get; set; }
    public List<Customer> CustomerList { get; set; }
}

This way you can create a new view from this controller action and select the ViewData class "HomeViewData" that will be passed to the view.  So your view will look like this.

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyMvcApplication.Models.HomeViewData>" %>
  
<asp:Content ID="aboutTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Customers
</asp:Content>
  
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Customers</h2>
    <% Html.Telerik().Grid(Model.CustomerList)
           .Name("CustomerGrid")
           .DataKeys(key => key.Add(c => c.ID))
           .Columns(column =>
           {
               column.Bound(c => c.CompanyName);
           })
           .Pageable()
           .Sortable()
           .Render(); %>
</asp:Content>

This is of course, works if you are using the Telerik ASP.NET MVC Extensions.  But your error message talks about GridView, and I'm pretty sure your best bet would be to use the MVC Grid instead of the GridView here.

I hope this helps.

I have sample applications, articles and video tutorials at my site: MVC Central - http://www.mvccentral.net.

King Wilder
Tags
General Discussions
Asked by
shanker bangari
Top achievements
Rank 1
Answers by
King Wilder
Top achievements
Rank 2
Share this question
or