-2

i am using MVC 4 with Razor Engine in my application,i needed to add the ASCX user control in partial view. But the question is How ?

Example :

FileName : PFDViewers.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PFDViewers.ascx.cs" Inherits="System.Web.Mvc.ViewUserControl" %>-
 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <asp:textbox runat="server"></asp:textbox>


Razor view:

@html.partialView("PFDViewers.ascx")

Is this possible to add the ASCX controls to Razor view.

Thanks in advance

Anaiah
  • 633
  • 7
  • 20
Neo Vijay
  • 823
  • 9
  • 13

2 Answers2

2

I don't know if this mix of webform and razor is considered very good practice. That said, could you create a partial view in your shared folder which contains the ascx code?

So you would say this in your razor view:

@Html.Partial("_MyASCXPartial")

Then ~/shared/_MyASCXPartial.cshtml would have your server control.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PFDViewers.ascx.cs" Inherits="System.Web.Mvc.ViewUserControl" %>-
 <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
<asp:textbox runat="server"></asp:textbox>
scgough
  • 5,099
  • 3
  • 30
  • 48
  • its working for with out using any servercontrol, if i use server controls not working and throw the below error, Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper – Neo Vijay Jun 11 '15 at 08:26
0

Yohh ..

@Html.Partial("_MyASCXPartial")

Then add this

   <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>"%>
 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <asp:textbox runat="server"></asp:textbox>

Just trying to help.

Anaiah
  • 633
  • 7
  • 20
  • exactly the same answer as i've already posted? – scgough Jun 11 '15 at 08:37
  • ooh .. im so shoorry .. but i haven't imitated yours .. maybe we just really had same answer and i didn't notice it .. – Anaiah Jun 11 '15 at 09:16
  • @scgough Or.. it takes 10 minutes to answer and they didn't notice you had answered *in the meantime*. Maybe Anaiah started their answer *before* you? Happens all the time. It's not like a copy+paste. Check the answer times. (just says '1hour' now) – freedomn-m Jun 11 '15 at 09:25
  • fair enough! I retract my statement. Apologies for any offence caused @Anaiah – scgough Jun 11 '15 at 09:26
  • Thanks @freedomn-m .. Yeah I bet that was what happened. – Anaiah Jun 11 '15 at 09:27
  • and @scgough .. No problem .. PEACE yow – Anaiah Jun 11 '15 at 09:28