0

I have a MVC6 web application, my page have 2 button: Submit and Print.

Submit will save the current value to the database.
Print will take the current value and open it in a new window.

But I'm not sure how to do the Print button because as far as I know you can't pass model to Actionlink <a> because it's a 'GET'.

How do I achieve this? Any response will be appreciated and apologize for bad english.

tickwave
  • 3,335
  • 6
  • 41
  • 82
  • 4
    No but you could pass the ID of the saved item, and then the print action can get the data from the database to display it – ADyson Jul 08 '19 at 06:48
  • With the help of Jquery Ajax Call you can use the same view page model. – Laxman Gite Jul 08 '19 at 06:54
  • @ADyson: Is there any other way beside saving it to the database? Because the PRINT function is more like a preview. I could actually save it to another table and remove it after but if there's an easier way I'd prefer that. – tickwave Jul 08 '19 at 07:11
  • do you want to print all data of page ? if yes you can print whole page using jquery and it show as preview of print like we are doing **ctrl+p** – Mustufa Jul 08 '19 at 07:40
  • Like @ADyson, Rather than calling db, If you pass model into your action method you could preview your model data using Save & Print Button. If you want to separate action you could use multiple form post like [Multiple Form Post](https://stackoverflow.com/questions/15788806/asp-net-mvc-4-multiple-post-via-different-forms) – Rabby Hasan Jul 08 '19 at 07:44
  • Well, if the model is being displayed currently on the page, the other potential option is to simply have a "print" version of the current page, using print-only CSS (this is done via media queries). Then you can use the browser's own print-preview screen without needing a separate action and view – ADyson Jul 08 '19 at 08:10
  • https://stackoverflow.com/questions/15095689/pass-object-through-html-actionlink-with-click . may be you are searching this. – zaman Jul 08 '19 at 09:51
  • 1
    Why does it need to be an anchor link? You can use a form with a submit button to do a post, and style the button to look like a link, if that's what you want. Do not make behavior dependent on presentation. Post it as it should be done, and then style it to look like you want. Also, there's no such thing as MVC6. It's ASP.NET Core. – Chris Pratt Jul 08 '19 at 13:36

0 Answers0