ASP.NET MVC加载网页内容转换成使用JQuery一个div [英] ASP.NET MVC Loading a page content into a div using JQuery

查看:257
本文介绍了ASP.NET MVC加载网页内容转换成使用JQuery一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC中的一个项目,我有这样的要求。

I'm using ASP.NET MVC in a project and I have a requirement like this..

它有一个主视图(Main.aspx)和操作方法来呈现主视图。而且我还有一个视图(SearchResult.aspx)和行动来呈现搜索结果的内容。我需要在异步加载的信息搜索结果页面用DIV主视图。有没有一种方法来实现这一目标?

It has one main View(Main.aspx) and a Action methods to render the main view. And I have another View (SearchResult.aspx) and Action to render the search results content. I need to load the SearchResult page asynchronously in to a DIV in the main View. Is there a way to achieve this?

谢谢 / BB

推荐答案

是啊,那是pretty的简单。假设你的控制器说,管理员和动作是用户,该页面的缺省路由/管理/用户。所以,你可以只使用.load方法jQuery来做到这一点,像这样:

Yeah that's pretty simple. Assuming your controller is say "admin" and the action is "users", your default route for that page is /admin/users. So you can just use the .load method in jQuery to do it like so:

$('#searchResults').load('/admin/users');

这假定主页与的SearchResult的ID一个div:

This assumes that the main page has a div with the ID of "searchResults":

<div id="searchResults"></div>

的操作只需要返回一个partialviewresult。当然,如果你设置了Global.asax中自定义路线或任何开关,出为我提供的示例网址。

The action just needs to return a partialviewresult. Of course if you set up a custom route or anything in global.asax switch that out for the example URL I provided.

这篇关于ASP.NET MVC加载网页内容转换成使用JQuery一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆