locked
Creating a new view RRS feed

  • Question

  • User-1025482824 posted

    I have an Items folder under view that has 'create', 'delete','edit', and 'Index'. On the web page when you click 'details' it takes you to another view called 'Special Items'. 'Special Items' has an index page and that's where it lands after clicking details. I want to create a "Print view" version of that index landing page. How can I add a new view to the 'Special Items' folder that can be accessed in the Item  web page index . Folder paths are as follows:

    Any recommendations are welcome, thank you

    ~View/Items/Index.cshtml

    ~Views/Special Items/Index.cshtml 

    Friday, June 29, 2018 7:22 PM

All replies

  • User283571144 posted

    Hi ruby888,

    According to your description, I suggest you could directly create a new view in the Special Items to show the print version of the index view.

    You could send some parameter to new action in the special item controller.

    Then you could create a button in the index.cshtml view to redirect the current page to print view.

    Like this:

    If you want to post something you could use below codes:

    @ using(Html.BeginForm("actionName", "controllerName")) { 
        <input type="submit" value="Some text" />
    }
       

    If you want to use a tag link

    @Html.ActionLink("some text", "actionName", "controllerName")
    

    Then you could write some codes to show the data inside the print cshtml.

    But if you just want to make the browser print current index page, I suggest you could consider using javascript function window.print();.

    Example:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Untitled Page</title>
    
        <script language="javascript" type="text/javascript">
            function printDiv(divID) {
                //Get the HTML of div
                var divElements = document.getElementById(divID).innerHTML;
                //Get the HTML of whole page
                var oldPage = document.body.innerHTML;
    
                //Reset the page's HTML with div's HTML only
                document.body.innerHTML = 
                  "<html><head><title></title></head><body>" + 
                  divElements + "</body>";
    
                //Print Page
                window.print();
    
                //Restore orignal HTML
                document.body.innerHTML = oldPage;
    
              
            }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="printablediv" style="width: 100%; background-color: Blue; height: 200px">
            Print me I am in 1st Div
        </div>
        <div id="donotprintdiv" style="width: 100%; background-color: Gray; height: 200px">
            I am not going to print
        </div>
        <input type="button" value="Print 1st Div" onclick="javascript:printDiv('printablediv')" />
        </form>
    </body>
    </html>

    Best Regards,

    Brando

    Monday, July 2, 2018 2:51 AM