将 ASP.NET AJAX 转换为 MVC - 什么是“等效”?服务器端事件?
我刚开始将 ASP.NET AJAX 编写的页面转换为 MVC。我是 MVC 架构模式的新手,正在尝试了解应该如何处理这两个事件——onloaddocklayout 和onsavedocklayout。它们是之前在我的 aspx.cs 页面中声明的服务器端事件。
有人能给我一个正确方向的碰撞吗?我发现这个线程,但我不认为这正是我正在寻找的?我应该在控制器中写一些代码吗?
<telerik:RadDockLayout ID="RadDockLayout1" Runat="server" onloaddocklayout="RadDockLayout_LoadDockLayout" onsavedocklayout="RadDockLayout_SaveDockLayout">
I am in the very beginnings of converting a page written in ASP.NET AJAX to MVC. I am new to the MVC architectural pattern and am trying to wrap my head around what should be done about these two events -- onloaddocklayout and onsavedocklayout. They were server-side events declared in my aspx.cs page before.
Could someone offer me a bump in the right direction? I found this thread, but I don't think that is quite what I'm looking for? Should I be writing some code down in the Controller?
<telerik:RadDockLayout ID="RadDockLayout1" Runat="server" onloaddocklayout="RadDockLayout_LoadDockLayout" onsavedocklayout="RadDockLayout_SaveDockLayout">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道您是否尝试在 MVC 3 页面内使用 Telerik 控件,但这不是您应该遵循的路径。您可以在 MVC 中使用一些 ASP.NET 控件,但仅限那些不依赖 ViewState 或页面回发的控件。
在 MVC 中,控制器和操作作为服务器端代码。所以这是你能做到的唯一方法,但我不认为你可以使用你的 Telerik 控件。
不过,您可以查看 Telerik 网站,他们有一些针对 ASP.NET MVC 的良好控件
I don't know if you're trying to use your Telerik control inside MVC 3 page but it's not the path you should follow. There is some ASP.NET controls you could use in MVC but only ones that doesn't rely on ViewState or page postback.
In MVC you have controllers and actions as a server side code. So it's the only way you can do it but I don't think you can use anyway your telerik control.
However you can check Telerik web site they have some good controls for ASP.NET MVC
作为一名 Webforms 人员,我也在尝试理解 MVC 及其哲学,我应该说它与 Webforms 完全不同。 Asp.net Webforms 封装了大部分内容,它具有视图状态,并且可以提供基于事件的机制,如 Windows 窗体应用程序。但这并不是 http 的实际工作方式。所以 MVC 有点回归基础,它没有按钮点击等。
视图只是普通的 html 控件(哦,是的,使用 HTMLHelper 扩展它会变得更容易)。你的控制器(在这种情况下,是的,你应该编写一个控制器)就像视图和存储库之间的桥梁。
控制器示例:
假设您有一个像这样的控制器,
在这种情况下,第一个 Action 方法类似于 Page_Load,而不是回发,另一个用 HttpPost 装饰的方法类似于带有 posback 的 Page_load。
您可能有点困惑我如何处理多个按钮:如何在 ASP.NET MVC Framework 中处理多个提交按钮?
相关主题:
https://stackoverflow.com/questions/46031/why-does- the-asp-net-web-forms-model-suck
我旁边有人没有获得 ASP.NET MVC 吗?
As a webforms guy, I am also trying understand MVC and its philosphy, and i should say its quite different then webforms. Asp.net webforms encapsulate most of the things under the hood that way it has viewstate and can provide event based mechanism like windows form application. But its not the actual way of how http works. So MVC is kind of back to basics and it doesnt have button clicks etc.
Views just normal html controls( oh yes with HTMLHelper extensions it gets easier) . Your controller ( in this case yes you should write a controller) is like a bridge between view and your repositories.
Controller Example:
lets say you have a controller like this
in this case first Action method is like Page_Load not postback, and the other one decorated with HttpPost acts like Page_load with posback.
You might have a little bit confused how can i handle multiple buttons: How do you handle multiple submit buttons in ASP.NET MVC Framework?
Related topics :
https://stackoverflow.com/questions/46031/why-does-the-asp-net-web-forms-model-suck
Does anyone beside me just NOT get ASP.NET MVC?
ASP.NET WebForms 中的服务器端事件在 ASP.NET MVC 中没有等效的映射。这是一个完全不同的范例。
Telerik 确实提供 MVC 产品线。如果您正在寻找对接框架,我确信那里有一些东西。
Telerik 的 Docking 控件只是 javascript 和 html。您可以反思它并发现它是如何工作的并编写您自己的!
使用 jQuery 进行高级对接
Server-side events in ASP.NET WebForms don't have an equivalent mapping in ASP.NET MVC. It's an entirely different paradigm.
Telerik does offer an MVC product line. If you are looking for a docking framework I'm sure there is something out there.
Telerik's Docking control is just javascript and html. You could reflect into it and discover how it works and write your own!
Advanced docking using jQuery