简体   繁体   English

带有jQuery Ajax调用的RenderBody

[英]RenderBody with jQuery Ajax calls

I'm think that I'm doing something wrong here in .Net Core. 我认为我在.Net Core中做错了什么

I have layout with @RenderBody 我有@RenderBody布局

Problem is - I'm doing jQuery Ajax calls, my Actions returning me Partial Views . 问题是-我正在执行jQuery Ajax调用,我的操作返回了Partial Views That works good. 很好

Problem is, I don't see any path of Controller and Action in URL , can't refresh page, I am returned to the Home . 问题是,我在URL中看不到ControllerAction的任何路径,无法刷新页面,我回到了Home

Another problem with Partials Views I can't solve is - Scripts : I can include all scripts in Layout , but some partials views requiring 2-3 scripts, another partials views different 2-3 scripts. 我无法解决的局部视图的另一个问题是- 脚本 :我可以在Layout中包含所有脚本,但是某些局部视图需要2-3个脚本,另一个局部视图需要不同的2-3个脚本。 I can't split usage, I don't want to throw all in one layout. 我无法拆分使用情况,我不想将所有内容都放在一个布局中。

Can't add them in the Partial View because jQuery loads on the end. 无法将它们添加到Partial View中,因为jQuery最终会加载。

If I include them on the end of the Layout page - then Click events and other stuff work when I navigate to different partials view. 如果我将它们包括在“ 布局”页面的末尾,那么当我导航到不同的局部视图时, 单击事件和其他内容将起作用。

I think my approach here is somewhere really bad, all my navigation is done by jQuery Ajax and returning Partial Views from the Controllers . 我认为这里的方法确实很糟糕,我所有的导航都是通过jQuery Ajax并从Controllers返回Partial Views完成的。

It's seems you're attempting to create a SPA (single page application) without actually understanding what goes into that. 似乎您在尝试创建SPA(单页应用程序)而没有真正理解其中的内容。

Right now, you're managing you application server-side, ie your routes are server-side, your views are server-side, etc. As a result, you need to go back and forth between the server to get your "pages", which negates the entire point of having a client-side application. 现在,您正在服务器端管理应用程序,即,路由是服务器端的,视图是服务器端的,等等。因此,您需要在服务器之间来回移动以获取“页面” ,这否定了拥有客户端应用程序的全部要点。 What you need to do is shuffle all of that client-side , using a framework like Angular, React, Vue, etc. 您需要做的是使用Angular,React,Vue等框架对所有客户端进行改组。

These frameworks will provide things for your like templates, two-way data-binding, client-side routing (including using things like the History API to create virtual URLs allowing you to browse back and forth, reload, etc. without losing your client-side state). 这些框架将为您提供诸如模板之类的东西,双向数据绑定,客户端路由(包括使用诸如History API之类的东西来创建虚拟URL,使您可以来回浏览,重新加载等),而不会丢失客户端,副状态)。 At that point, your backend ASP.NET Core app becomes more like an API, simply handling data transfer to/from your client-side app and something like your database, etc. 那时,您的后端ASP.NET Core应用变得更像一个API,只需处理与客户端应用以及数据库之类的数据传输。

You might also be interested in Blazor, particularly server-side Blazor. 您可能也对Blazor感兴趣,尤其是服务器端Blazor。 It's very early in development, so it's probably not a good idea to start building mission-critical apps on it, yet., but it does provide a much more fluid server-side to client-side experience. 这是一个在发育早期 ,所以它可能不启动就可以了建设任务关键型应用程序,但是,一个好主意,但它确实提供了一个更加流畅的服务器端对客户端的体验。 Essentially, it creates reactive HTML documents that use SignalR under the hood to communicate back to the server transparently to get/update state and keep the server-side and client-side portions in sync. 本质上,它创建了反应性HTML文档,这些文档在后台使用SignalR透明地与服务器通信以获取/更新状态,并使服务器端和客户端部分保持同步。 It's pretty slick, but like I said, still very much a "preview" at this point. 这很漂亮,但是就像我说的那样,在这一点上仍然是一个“预览”。

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

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