简体   繁体   English

在MVC视图页面中运行服务器控件? (asp.net)

[英]Running a server control inside an MVC view page? (asp.net)

Is this possible? 这可能吗? if so, what adjustements do i need to make in order to do this properly. 如果是这样,我需要进行哪些调整才能正确执行此操作。 I know i can run webforms and mvc views in seperate files, but i want to run the web server control output and events in/on the mvc view page, however, i keep getting this compiler error: 我知道我可以在单独的文件中运行webforms和mvc视图,但我想在mvc视图页面中/上运行Web服务器控件输出和事件,但是,我不断收到此编译器错误:

    Line 38: <CuteWebUI:Uploader ID="UploadPic" runat="server" UploadType="IFrame" 
Line 39:       FileTooLargeMsg="{0} cannot be uploaded! File size ({1}) is too large. The maximum file size allowed is set to: {2}." 
Line 40:       TempDirectory="~/UserData/Images/TemporaryImages" UploadingMsg="Uploading..."

    C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0> "C:\Windows\Microsoft.NET\Framework\v4.0.30128\vbc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Routing\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Routing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Entity.Design\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Entity.Design.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Entity\v4.0_4.0.0.0__b77a5c561934e089\System.Web.Entity.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Abstractions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Abstractions.dll" /R:"C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\assembly\dl3\1ebf4e16\00022dff_30cfca01\CuteWebUI.AjaxUploader.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\App_global.asax.dwhl4wn6.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Entity\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Entity.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\assembly\dl3\f5e0c238\003699d9_86d1ca01\LSL.DLL" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\2.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\App_Web_zkzcodji.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /out:"C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\App_Web_tptbtllk.dll" /D:DEBUG=1 /debug+ /win32resource:"C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\tptbtllk.res" /nowarn:41008 /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Collections.Specialized,System.ComponentModel.DataAnnotations,System.Configuration,System.Data.Entity.Design,System.Data.Linq,System.Linq,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.DynamicData,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls,System.Xml.Linq,System.Web.Mvc,System.Web.Mvc.Ajax,System.Web.Mvc.Html,System.Web.Routing /warnaserror- /optionInfer+  "C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\App_Web_tptbtllk.0.vb" "C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\App_Web_tptbtllk.1.vb" "C:\Users\Jay\AppData\Local\Temp\Temporary ASP.NET Files\root\6ea46d42\947d937c\App_Web_tptbtllk.2.vb"


Microsoft (R) Visual Basic Compiler version 10.0.30128.1
Copyright (c) Microsoft Corporation.  All rights reserved.

X:\!My Programs\Web Sites\LSL\Views\Home\Index.aspx(38) : error BC30456: 'OnFileUploaded' is not a member of 'ASP.views_home_index_aspx'.

            AddHandler __ctrl.FileUploaded, AddressOf Me.OnFileUploaded
                                                      ~~~~~~~~~~~~~~~~~
X:\!My Programs\Web Sites\LSL\Views\Home\Index.aspx(38) : error BC30456: 'OnFileUploaded' is not a member of 'ASP.views_home_index_aspx'.

            RemoveHandler __ctrl.FileUploaded, AddressOf Me.OnFileUploaded
                                                         ~~~~~~~~~~~~~~~~~

i don't know what else do do, it just wont recognize the control name when im writing the event signature, right after the "handles" keyword, comes the server control name and then a dot, and then the event name, but as events its just giving me "Me", "MyBase" and "MyClass" options to run events for... doesn't let me access "FileUpload.OnFileUploaded" which is the control name & event name i want to write the sub routine method declaration (and subsequently method) and signature for. 我不知道该怎么办,当我在编写事件签名时,在“ handles”关键字之后,它只是无法识别控件名称,先是服务器控件名称,然后是一个点,然后是事件名称,但是事件只是给我“ Me”,“ MyBase”和“ MyClass”选项来运行事件...不允许我访问“ FileUpload.OnFileUploaded”,这是我要编写子例程的控件名称和事件名称方法声明(以及随后的方法)和签名。

I don't think you can do this 我不认为你能做到

Perhaps you could make it compile by adding a code-behind for your view, and adding the method, that you are trying to hook up to the event. 也许可以通过在视图中添加代码隐藏并添加方法来使其编译,以使您尝试连接事件。

But remember, the MVC page lifecycle is very different than the one of WebForms. 但是请记住,MVC页面的生命周期与WebForms的生命周期有很大不同。 Most WebForms controls depends on the WebForms lifecycle to do their work; 大多数WebForms控件都依赖于WebForms生命周期来完成其工作。 and if the right events don't get fired, etc, the control will fail. 如果未触发正确的事件等,则控件将失败。 Also, a simple thing as missing the viewstate in MVC will create problems for many controls. 同样,缺少MVC中的视图状态的简单事情也会对许多控件产生问题。

If you really want to; 如果你真的想 perhaps you can make all the plumbing work required to satisfy your control. 也许您可以进行所有水暖工作来满足您的控制需求。 But it will be a lot of work, without any real benefit. 但这将是很多工作,没有任何实际好处。 I think you are better off making the Page a normal WebForms Page, if you really need to use that control. 我认为如果确实需要使用该控件,最好将Page设置为普通的WebForms页面。 (I think there are good, free file-upload controls available for MVC you could use instead). (我认为您可以使用MVC的免费文件上传控件,这些控件可以免费使用)。

Please see the ASP .NET WebForms Page Lifecycle , as opposed to the MVC Page Lifecycle , and this question . 请参阅ASP.NET WebForms页面生命周期 ,而不是MVC页面生命周期 ,以及此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM