我们能从单个控制器显示2个不同的视图吗? [英] Can we show 2 different view from single controller ?

查看:48
本文介绍了我们能从单个控制器显示2个不同的视图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有列表页面和列表页面的添加/编辑页面。当我将添加/编辑任何数据然后点击按钮时会出现打印数据的警告信息。



1.如果用户点击是,那么我必须在单个控制器的新选项卡中显示列表页面视图和另一个打印页面视图。



2.如果用户点击否,我只能从单个控制器显示列表页面视图。





是否可以在目标空白的锚点按钮上显示来自单个控制器的2个不同视图。

解决方案

好的在重新审核之后,我意识到这是一个仅限JavaScript的解决方案。



 <   script     type   =  text / javascript >  
var linkClicked = function (){
var confirm = window .confirm(' 打印?);
if (已确认){
window .open(' @ Url.Action(PrintAction,Controller)'' _ blank');
}
}
< / script >





And链接:

 @ Html.ActionLink( 请点击我 操作   Controller,null,new {onclick = linkClicked() }) 


只有一个响应,因此您无法使用一个控制器发送两个视图。您发送的视图浏览器需要包含一些打开打印视图页面的javascript。它基本上就是解决方案2中的内容,只会在页面加载时运行而不是单击事件。



 <   script     type   =  text / javascript >  
window.open(....);
< / script >





如果你想在一个新的标签页中你可以把一个打印页面的表格作为动作,方法就像GET一样目标为_blank并通过js而不是使用window.open提交表单。


我已经在部分视图中使用以下代码完成了



< a href =   @ Url。操作( methodname =   controllername =  ,new {id = Model.Id}) id =  < span class =code-string> btnQRPrint target =   _ blank >  < /   a  >  



< script >
var qr = jQuery .noConflict();
qr(窗口).load(function(){
debugger;
var val = ' @ Html.Raw(TempData [ID])';
if (val > 0 ){
qr( #btnQRPrint)[ 0 ]。click();
}
});
< / script >


I have list page and add/edit page of list page.When i will Add/Edit any data then on button click there is alert message of printing data.

1. If user will click on "yes" then i have to show list page view and another print page view in new tab from a single controller.

2. If user will click on "no" then i have to show list page view only from single controller.


Is it possible to show 2 different view from single controller on anchor button click with target blank.

解决方案

Okay, after re-reviewing, I realize that this is a JavaScript-only solution.

<script type="text/javascript">
   var linkClicked = function(){
      var confirmed = window.confirm('Print?');
      if(confirmed){
         window.open('@Url.Action("PrintAction","Controller")','_blank');
      }
}
</script>



And the link:

@Html.ActionLink("Click Me","Action","Controller,null,new { onclick="linkClicked()" }) 


There is only one response so you can't send two views with one controller. The view you send to the browser will need to contain some javascript that opens the print-view page. It'll basically be what is in "Solution 2" only will just run as the page loads rather than on a click event.

<script type="text/javascript">
    window.open( .... );
</script>



If you want it in a new tab you could put a form with the print page as the action, the method as GET and the target as "_blank" and submit the form via js rather than using window.open.


I have already done it in partial view with the below code

<a href="@Url.Action(" methodname=", " controllername=", new { id = Model.Id })" id="btnQRPrint" target="_blank"></a>



<script>
    var qr = jQuery.noConflict();
    qr(window).load(function () {
        debugger;
        var val = '@Html.Raw(TempData["ID"])';
        if (val > 0) {
            qr("#btnQRPrint")[0].click();
        }
    });
</script>


这篇关于我们能从单个控制器显示2个不同的视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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