网站建设销售话术,广州建网站公司,昆山网站推广,学开网店哪个培训机构好正规如何使用Ajax加载以HTML呈现的完整部分视图(所以我只设置了div.html)我需要一个Ajax调用来调用控制器操作#xff0c;它将呈现一个完整的局部视图(红色)#xff0c;并将其附加到当前加载的视图的末尾#xff1f;[我知道如何附加到DOM以及如何进行Ajax调用]我需要知道什么是最…如何使用Ajax加载以HTML呈现的完整部分视图(所以我只设置了div.html)我需要一个Ajax调用来调用控制器操作它将呈现一个完整的局部视图(红色)并将其附加到当前加载的视图的末尾[我知道如何附加到DOM以及如何进行Ajax调用]我需要知道什么是最好的管道方法操作应该返回什么类型的操作结果如果有一个内置的机制来避免重新发明轮子return Partialview(_PartialViewName)并使用$.load调用返回partialview的控制器方法从从Ajax调用的控制器操作返回partialView作为actionResult会返回呈现的HTML吗这样我就可以把它放到DIV中了。你不需要ajax只要用$.load。好的谢谢我需要研究一下.load是如何使用的。谢谢 1任何时候…快乐编码)Guruprasad Rao建议使用$(selector).load(urldatacallback)是目前最好的解决方案。ASP.NET MVC中有内置的Ajax帮助程序可以涵盖基本场景。您需要安装并引用jquery.unobtrusive-ajaxjavascript库(jquery依赖项)。然后在主视图(比如index.cshtml)中输入以下代码索引文件Ajax.ActionLink(Load More Posts,MorePosts, new AjaxOptions(){HttpMethod GET,AllowCache false,InsertionMode InsertionMode.InsertAfter,UpdateTargetId posts-wrapper})注Ajax.ActionLink助手接受AjaxOptions参数进行更多的自定义。在控制器(比如homecontroller.cs)中您应该返回PartialViewResultpublic ActionResult MorePosts(int? offset, int? count){IEnumerable posts myService.GetNextPosts(offset, count);return PartialView(posts);}最后定义moreposts.cshtml部分视图model IEnumerable{Layout null;}foreach (var post in Model){post.Prop1post.Prop2}就是这样。当一些用户点击Load More按钮时将加载更多的文章。注1您可以实现OnBegin功能来实现决定下一个要加载的日志的实际逻辑(例如获取上一个加载日志的ID并将其发送到服务器)。注2使用自定义jQuery.ajax调用(不使用jquery.unobtrusive)可以获得相同的结果。唯一的区别是手动Ajax调用和单击事件。希望这有帮助。如果需要我可以写一个更完整的例子。这与我的黑莓手册的方法使呼叫使用Ajax时美元就可以知道全.ajax track errors。谢谢Please请维克多how to make this美国导游手册参数自动呼叫as与which we will not get on Main View。我建议从nuget获取Westwind.Web.Mvc库您可以将任何视图运行到字符串中作为JSON结果返回。public JsonResult GetPosts(){string postsHtml ViewRenderer.RenderPartialView(~/views/yourcontroller/_PostsPartial.cshtml,model);return Json(new { html postsHtml });}正如guruprasad在评论中所说您可以使用return PartialView(model)从MVC控制器返回部分视图但使用renderpartialview您可以将其作为字符串输出并在需要时将其与任何其他值一起输出为json。如果您选择使用WebAPI这将有效因为它不具备呈现内置视图的能力。你可以进入HTML渲染全部粘在JSON的物业这是方便的。viewrenderer.renderpartialview is also方便。谢谢我会查厂for this。读你的帖子invisiblepanda 它不让它(这)样partialview does the viewrenders out to a字符串。如果你使用webapi You probably不应该回来好的HTML。我freedomn米高度disagree with that声明ASP.NET MVC和Web API控制器和controllers are the same thing in the latest基本版本他们都是统一的。卢克只是因为茶有双控制器的句法相似的意思他们不均值for the same thing。Web API to handle is商业逻辑whereas ASP.NET MVC的Viewpresentation should处理逻辑。以保存你的业务层分离的关注should not the view of定义你的布局例如HTML。of this is the the福利消费能力to the same在多不同的APIvastly前端应用。for instanceWindows应用程序# 10 C安安和浏览器应用程序的HTML 5含Objective-C的程序。我丹that this with You to同意趋势不好茶的最佳实践它会更好那么返回值和render to the standard with or something to a角。不管一个人多关注的是在分离of the play with the壳层和modularisation of the is not necessarily尾巴什么使你通过the values to view。在这房子是分离the the view is between the渲染和生成viewmodel is for the view that仍然分离这只是你使用the method to HTML产生不同的最终结果。你不同意吗它是真正的卢克there may be when both the时代逻辑和业务逻辑在Web API reside the presentation and the前端项目应用模拟presenter which is just吐出来的结果。虽然在这神奇的房子为什么你有一个前端应用在所有当there may be some缓存相关的原因使静电to on the pages for高scalability服务器的方法与启动就不会recommend consideration没有认真。处理客户需求给你regardless of error to You can never建筑的决定我真的真的有一个愚蠢的前端。卢克也for which the original Comment with context你disagree高度stated [ D ]You probably be HTML不应该回来You should not不返回HTML。我认为这是公平的说回来commonly is the less有用的HTML设计。对不起如果我似乎在混乱位有一些啤酒我想make the Point is that the logic view是曼弗雷迪或法拉利吗或是业务逻辑应该在webapi reside说恩我不应该。有一个简单的方式提供给webapi from within a view to。the view is the view that和我仍然可以作为模型is generated from the商务逻辑层controllers between that can be shared webapi controllers和MVC。我也喜欢我的disagree to change)somewhat disagree高度