使用链接按钮在多视图中显示不同的web页面

时间:2022-05-08 01:28:04

I have developed a web site on ASp.net 3.5 with VB which have multiple pages the problem is i want to show all pages in one view user click on link button and coprresponding page should open on single page then user click to other link button and another page open in same browser window with same layout.Please suggest me what should i do?

我开发了一个网站ASp.net 3.5与VB多个页面的问题是我想在一个视图显示所有页面用户点击链接按钮,coprresponding页面应该打开单页然后用户点击其他链接按钮,另一个页面在同一个浏览器窗口打开相同的布局。请建议我该怎么做?

1 个解决方案

#1


1  

You could use AJAX to achieve this. So for example let's suppose that you have multiple controller actions that return partial views. You could then create links on your page to those actions:

您可以使用AJAX实现这一点。例如,假设有多个控制器动作返回部分视图。然后你可以在你的页面上创建这些动作的链接:

<%= Html.ActionLink("page 1", "Page1", "SomeController", null, new { id = "link1" }) %>
<%= Html.ActionLink("page 2", "Page2", "SomeController", null, new { id = "link2" }) %>
<%= Html.ActionLink("page 3", "Page3", "SomeController", null, new { id = "link3" }) %>

and 3 corresponding placeholders where the pages would be loaded:

以及3个相应的占位符:

<div id="page1" />
<div id="page1" />
<div id="page1" />

you could now AJAXify those links in a separate javascript file. Example with jquery:

现在可以在一个单独的javascript文件中对这些链接进行AJAXify。与jquery示例:

$(function() {
    $('#link1').click(function() {
        $('#page1').load(this.href);
        return false;
    });
    $('#link2').click(function() {
        $('#page2').load(this.href);
        return false;
    });
    $('#link3').click(function() {
        $('#page3').load(this.href);
        return false;
    });
});

I would also strongly recommend you going through the tutorials on the ASP.NET MVC site.

我还强烈建议您阅读有关ASP的教程。净MVC的网站。

#1


1  

You could use AJAX to achieve this. So for example let's suppose that you have multiple controller actions that return partial views. You could then create links on your page to those actions:

您可以使用AJAX实现这一点。例如,假设有多个控制器动作返回部分视图。然后你可以在你的页面上创建这些动作的链接:

<%= Html.ActionLink("page 1", "Page1", "SomeController", null, new { id = "link1" }) %>
<%= Html.ActionLink("page 2", "Page2", "SomeController", null, new { id = "link2" }) %>
<%= Html.ActionLink("page 3", "Page3", "SomeController", null, new { id = "link3" }) %>

and 3 corresponding placeholders where the pages would be loaded:

以及3个相应的占位符:

<div id="page1" />
<div id="page1" />
<div id="page1" />

you could now AJAXify those links in a separate javascript file. Example with jquery:

现在可以在一个单独的javascript文件中对这些链接进行AJAXify。与jquery示例:

$(function() {
    $('#link1').click(function() {
        $('#page1').load(this.href);
        return false;
    });
    $('#link2').click(function() {
        $('#page2').load(this.href);
        return false;
    });
    $('#link3').click(function() {
        $('#page3').load(this.href);
        return false;
    });
});

I would also strongly recommend you going through the tutorials on the ASP.NET MVC site.

我还强烈建议您阅读有关ASP的教程。净MVC的网站。