简体   繁体   English

Webform母版页MVC PartialRender服务器事件未触发

[英]Webform Master page MVC PartialRender server event not firing

OK so I have a webforms project I am wanting to start doing MVC instead. 好的,所以我有一个Webforms项目,我想开始做MVC。 I would like the MVC pages to use the Webforms master page until I can get things transferred over more to MVC. 我希望MVC页面可以使用Webforms主页,直到可以将更多内容转移到MVC为止。 I have this working with a solution I have found you can find listed below (This project works really well except the server event) 我使用此解决方案找到了下面列出的解决方案(除了服务器事件,该项目确实运行良好)

https://github.com/MicahArmantrout/BlackMagicMVC https://github.com/MicahArmantrout/BlackMagicMVC

在此处输入图片说明

My problem is that server side events in the master page are not firing. 我的问题是母版页中的服务器端事件未触发。 When you load the project up if you click on "Click Me!" 当您加载项目时,如果单击“单击我!” the button will fire a server event and the Text will change to "You clicked me". 该按钮将触发服务器事件,并且文本将更改为“您单击了我”。

在此处输入图片说明

If you goto "Click For MVC" (Which is a MVC Partial Render) and then click the "Click Me!" 如果转到“ Click For MVC” (这是MVC部分渲染),然后单击“ Click Me!”。 the server event never fires. 服务器事件永远不会触发。 Any idea why and if this can be fixed ? 知道为什么以及是否可以解决?

Note: This is not just a exercise I have a place in a application where this would be extremely useful.If you want to understand this project more please see 注意:这不仅是练习,我在应用程序中还有一个非常有用的地方。如果您想了解更多该项目,请参阅

http://trycatchfail.com/blog/post/ASPNET-MVC-3-Razor-C-and-VBNET-WebForms-A-Tale-of-Black-Magic-Voodoo.aspx http://trycatchfail.com/blog/post/ASPNET-MVC-3-Razor-C-and-VBNET-WebForms-A-Tale-of-Black-Magic-Voodoo.aspx

There is no concept of server side events in MVC. MVC中没有服务器端事件的概念。 And MVC is not going to wire up the client side events and translate them to server side event handlers the way ASP.Net WebForms does. 而且MVC不会像ASP.Net WebForms那样连接客户端事件并将其转换为服务器端事件处理程序。

You have these options: 您有以下选择:

  • Recreate master page in MVC ( _Layout.cshtml ) and then handle button clicks in your controller. 在MVC( _Layout.cshtml )中重新创建母版页,然后处理控制器中的按钮单击。 Depending on your design, some refactoring would be needed. 根据您的设计,将需要一些重构。 You need to decide how or who handles those button clicks. 您需要确定如何或由谁来处理这些按钮单击。 You can probably get away with handling some of them in a Base Controller, but I would suggest to take a second look at what you're doing in master and how you can translate them on MVC. 您可能可以在基本控制器中处理其中的一些内容,但是我建议您再看一看您在master中所做的工作以及如何在MVC上转换它们。
  • Do the other way round - define you master page in MVC, and render that in your webforms. 反过来做-在MVC中定义您的母版页,并在您的Webforms中呈现它。

Ideally, your master page should not be having any business functions anyway. 理想情况下,您的母版页无论如何都不应具有任何业务功能。 It should be nothing more than Navigation and style. 它只不过是导航和样式。 As long as you adhere to this, migrating to MVC won't be that painful. 只要您坚持这一点,迁移到MVC就不会那么痛苦。

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

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