MVC PartialViewResult

  1. #1

    MVC PartialViewResult

    Hi,
    I try to display a partial view by using the following controller code:
     public class SharedController : System.Web.Mvc.Controller
        {
    
           
            public ActionResult PartialView1(string containerId)
            {
                Ext.Net.MVC.PartialViewResult r = new System.Web.Mvc.PartialViewResult(containerId);
               
                r.ContainerId = containerId;
                r.RenderMode = RenderMode.AddTo;
                r.SingleControl = true;
                return  r;
               
            }
     }
    when the view is suppose to be loaded the view does not show up, and in FireBug I see the following error message.
    Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP.views_shared_partialview1_ascx' to type 'System.Web.Mvc.ViewUserControl'.
    when I use System.Web.Mvc.PartialViewResult instead of System.Web.Mvc.PartialViewResult the error disappear.

    in all the sample codes I read, that System.Web.Mvc.PartialViewResult should be used.

    any advice how to use it?

    thanks
    Gerald
  2. #2
    Please post that view
  3. #3
    Quote Originally Posted by Vladimir View Post
    Please post that view
    Here ist comes
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PartialView1.ascx.cs"
        Inherits="ContractPortalMVC.Views.Shared.PartialView11" %>
    <ext:ResourceManager ID="ResourceManager1" runat="server" CleanResourceUrl="false" />
    <ext:Container ID="Container1" runat="server" IDMode="Static" StyleSpec="background-color: yellow;"
        Html='<%# DateTime.Now %>' AutoDataBind="true" />
    <%--<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <div>
        this is a partial view
        </div>
    </body>
    </html>--%>
  4. #4
    - ResourceManager sgould not be presented in the partial view, you have to remove it
    - What a base class for ContractPortalMVC.Views.Shared.PartialView11?
  5. #5
    Quote Originally Posted by Vladimir View Post
    - ResourceManager sgould not be presented in the partial view, you have to remove it
    - What a base class for ContractPortalMVC.Views.Shared.PartialView11?
    removing the ResourceManager did not change anything.

    here is the codebehind where you can see the base class
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace ContractPortalMVC.Views.Shared
    {
        public partial class PartialView11 : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
        }
    }
  6. #6
    Partial view must be inherited from 'System.Web.Mvc.ViewUserControl'
  7. #7
    Quote Originally Posted by Vladimir View Post
    Partial view must be inherited from 'System.Web.Mvc.ViewUserControl'
    Now it works,

    thanks
    Gerald

Similar Threads

  1. [CLOSED] [MVC] Set Active Tab with PartialViewResult
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 23, 2012, 6:18 PM
  2. [CLOSED] Migrating to 2: PartialViewResult
    By PhilG in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: May 21, 2012, 9:27 AM
  3. MVC + PartialViewResult And Model
    By barroei in forum 1.x Help
    Replies: 3
    Last Post: Feb 15, 2011, 3:30 PM
  4. [CLOSED] PartialViewResult Controls in MVC 2
    By tiramisu in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Apr 26, 2010, 9:05 AM
  5. [CLOSED] PartialViewResult Problem
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jan 27, 2010, 11:15 AM

Posting Permissions