Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 07, 2012 05:12 PM by CodeHobo
Aug 07, 2012 02:55 PM|LINK
The need is to host a customer ASP.NET control in an ASP.NET MVC application. The custom ASP.NET control that I am trying to host in ASP.NET MVC application has an HttpHandler in it which deals with image rendering.
I have placed the custom ASP.NET control inside a Site.Master page and DataBinding of the custom control is written in the Site.Master.cs page inside an ASP.NET MVC application.
Now the problem that I am facing is that the custom ASP.NET control gets rendered whereas the HttpHandler used by the custom ASP.NET control couldn’t be recognized. Also, I have added the HttpHandler details inside the web.config file as well.
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="MVCSample.Views.Shared.Site1" %>
<%@ Register Assembly="XXXX, Version=XXXXX, Culture=neutral, PublicKeyToken=XXXXX"
Namespace="XXXXXX" TagPrefix="cc1" %>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<cc1:XXXXX ID="XXXXX" runat="server" Height="200px" Width="200px" ClientIDMode="AutoID" />
public partial class Site1 : System.Web.UI.MasterPage
protected void Page_Load(object sender, EventArgs e)
<Binding code for the control>
<add path="XXXX.ashx" verb="*" type="XXXXXXXX"/>
Any help on this would be appreciated.
Thanks in advance.
Aug 07, 2012 05:12 PM|LINK
You should not be using server controls or custom user controls in an ASP.NET MVC application. ASP.NET MVC doesn't work with server controls. Server controls rely on ViewState and ASP.NET MVC does not have ViewState.
If you want to serve images you can create an MVC action method that returns a FileResult and then create a partial view that includes an image tag with the src referecing that action method. You can then reuse the partial view in any of your views.
You can also use WebApi instead of an mvc action if you like.