简体   繁体   English

iframe / script是在ASP.NET MVC中具有多个独立控件的唯一方法吗?

[英]Are iframes/script the only ways to have multiple independent controls in ASP.NET MVC?

Besides using script or an iframe, is there any way to get independently operating views/actions working on a single page? 除了使用脚本或iframe,是否有任何方法可以使在单个页面上进行独立操作的视图/操作? For example, suppose I have a Delete page for FabWidgets. 例如,假设我有一个FabWidgets的Delete页面。 It might look like: 它可能看起来像:

Are you sure you want to delete this FabWidget "<%= Model.Name %>"?

Careful, this FabWidget controls these FrobNozzles:

<% Html.RenderAction("Grid", "FrobNozzles") %>

<!-- Form for delete/cancel -->

So far so good... unless the FrobNozzle's Grid view is really big and needs to do paging. 到目前为止一切顺利...除非FrobNozzle的Grid视图确实很大并且需要进行分页。 If the normal paging actions happen, we'll just navigate off the delete page. 如果发生正常的分页操作,我们将仅浏览删除页面。 How can we get the paging for the FrobNozzle's Grid? 我们如何获得FrobNozzle网格的分页?

I see possibilities in sticking the grid inside an iframe, so it can just render like normal and handle new itself as needed, without messing up the current page. 我看到了将网格粘贴到iframe中的可能性,因此它可以像正常一样进行渲染并根据需要处理新的自身,而不会弄乱当前页面。 There's also a way using script to do ajax requests and redisplay or whatnot. 还有一种使用脚本执行ajax请求并重新显示或其他方式的方法。

Is there any simple ASP.NET MVC integration to make this just work without having to really deal with it much? 是否有任何简单的ASP.NET MVC集成使它能够正常工作而无需太多处理? For example, in ASP.NET WebForms, the ViewState postback would just let us have the FrobNozzle grid fire off events without messing up the rest of the page. 例如,在ASP.NET WebForms中,ViewState回发将仅使我们使FrobNozzle网格触发事件,而不会弄乱页面的其余部分。 Any "magic" like that for ASP.NET MVC? 像ASP.NET MVC这样的“魔术”吗?

I did look at partial and so on, but didn't see how it handles the postback issue. 我确实查看了partial等,但没有看到它如何处理回发问题。

This is one of the things that differentiates MVC from WebForms. 这是将MVC与WebForms区别开的东西之一。 If you want to do something like this, you'll need to write some code to handle the paging. 如果您想做这样的事情,则需要编写一些代码来处理分页。

You could pass a "PostbackUrl" to the Grid action, and the Grid action could use that Url whenever it pages the data (appending its paging args to the querystring). 您可以将“ PostbackUrl”传递给Grid操作,并且Grid操作可以在分页数据时使用该Url(将其分页args追加到querystring上)。 Or you could pass "PostbackRouteData", which would be a set of route values to use when generating paging links (again, the Grid would add its paging args to the route data). 或者,您可以传递“ PostbackRouteData”,它是生成分页链接时要使用的一组路由值(同样,网格会将其分页参数添加到路由数据中)。

I would actually suggest using the Ajax helpers here (Ajax.ActionLink would work great for the paging), but if you really need to avoid IFrames and JavaScript, you'll have to roll your own solution. 我实际上建议在这里使用Ajax帮助器(Ajax.ActionLink在分页时会很好用),但是如果您确实需要避免使用iframe和JavaScript,则必须推出自己的解决方案。

MVC gives you a lot of control over the rendering, which can be an advantages. MVC为您提供了许多对渲染的控制,这可能是一个优点。 However, you lose the "Windows-like" event-driven programming model of WebForms. 但是,您将丢失WebForms的“类似于Windows”事件驱动的编程模型。

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

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