在 asp.net mvc 中路由 webform
我有一个 ASP.NET MVC 应用程序,并且有一个在 MVC 中构建的 WebForm 页面,因为有一个关于如何做我需要做的事情的教程,但它都是 WebForm 风格的。我试图弄清楚如何以 MVC 格式做同样的事情,但无法弄清楚。所以我需要弄清楚如何在我的 MVC 应用程序中使用此页面。但是,当我尝试转到该页面时,它给出错误“页面不能从 ViewMasterPage 派生,除非页面从 ViewPage 派生。”所以我还必须制作一个新的标准 MasterPage。
情况是这样的。我有一个位于 MVC ViewMasterPage 中的搜索栏,该搜索栏位于从它派生的每个页面上。用户在搜索栏中提交信息后,它会调用 WebForm Search.aspx 页面并在 Search.aspx 页面上显示结果。我希望 URL 类似于“http:///search//。Search.aspx 页面位于项目的根目录中。我如何获得我正在寻找的结果?谢谢!
I have an ASP.NET MVC app and I have a WebForm page I built in the MVC due to a tutorial on how to do something I needed to do, but it was all in WebForm style. Ive tried to figure out how to do the same thing in MVC format but cant figure it out. So I was needing to figure out how to use this page in my MVC app. But when I try to go to the page, it gives me the error "Page cannot be derived from ViewMasterPage unless Page derives from ViewPage." So I had to make a new standard MasterPage also.
The situation is this. I have a search bar located in the MVC ViewMasterPage thats on every page that is derived from it. Once a user submits info in the search bar, it calls the WebForm Search.aspx page and displays the results on the Search.aspx page. I want the URL to be like "http:///search//. The Search.aspx page is located in the root of the project. How would I get the results Im looking for? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想要在正确的 MVC 中重新实现该 Web 表单。如果您知道自己在做什么,那么两者可以在同一个 Web 应用程序中很好地协同工作,但是如果您尝试在 MVC 中实现整个事情,那么只坚持偶尔使用页面的 Web 表单教程可能会有所帮助。整个事情变得更加难以支持。 (正如您已经从必须制作第二个母版页中学到的那样。)
学习教程,但要重点了解他们正在做什么,而不仅仅是复制/粘贴代码。您端的实际实现听起来应该保留在 MVC 中。
You're probably going to want to re-implement that web form in proper MVC. The two can play nice together in the same web app if you know what you're doing, but if you're trying to implement the whole thing in MVC then just sticking with a web forms tutorial for the occasional page is probably going to make the whole thing a lot more difficult to support. (As you've already learned from having to make a second master page.)
Study the tutorials, but make it a point to learn exactly what it is they're doing rather than just copy/paste the code. The actual implementation on your end sounds like it should stay in MVC.
ASP.NET WebForms 绝对可以处理路由。我最近构建了一个非常大的网站,它完全是 WebForms 且完全路由的。除了 Viewstate 和其他形式垃圾之外,没有公开迹象表明它是一个 aspx 站点。
您可能需要稍微调整一下,具体取决于您的 URL 结构、您打算如何让搜索条件进入页面,但它会起作用。
ASP.NET WebForms can absolutely handle the routing. I've recently built a very large site that is completely WebForms and completely routed. There is no public indication that it is an aspx site other than Viewstate and the other tell-tale form garbage.
You might need to tweak this a little depending up your URL structure, how you intend for the search criteria to come into the page, but it will work.