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