What I try to achieve:
Convert a MVC3 view to PDF with abcpdf 8.
It is a result view where I want to cut off party of the views DOM like navigation and other website related parts.
Abcpdf needs, in order to render the html with all css formattings correctly, a absolute url. But I don't want to show the result-pdf view to the user. So how can I access a view from controller by URL without displaying the view. The original result view shall be displayed all the time.
Thank you in advance
Christian
You cannot access a View directly with MVC, you have to go through a Controller method. In ASP.NET MVC, URLs map to Controller methods, not to Views.
So if you know the URL of the Controller method that calls the View, you can take that URL and pass it to ABCPDF.
Related
I am developing a movie library application in asp.net. In admin page, I need to add a movie to the database(details such as name, actors, poster url). And also I need to upload the trailer of the movie to a specific folder in the server.
In my AddMovie View(which is strongly typed to a MovieDetails Model), I have a forms to include movie information as text and with a file input to upload a file(movie trailer). Within my controller I get the binded MovieDetails model and the uploaded file seperately as two parameters as follows.
At first I just posted from my view to this controller without using ajax. I was able to get the Model and the file to the controller to do what I needed to do.
Then I moved to ajax and tried to do this without page refresh.
Now no files cannot be uploaded. I tried to debug and noticed that uploadFile parameter of the controller is null although I attached a file to the file input in the view.
Is there any way to post the model to the controller and upload the file without completely changing the controller and using a single ajax call?
Or else is it possible pass the file path through a model attribute, access that file path and upload the relevant file in the controller, using Ajax.
Thank you!
As Darin mentioned, there is no simple way to handle file-uploading matters via ajax for some security reasons and you can't upload files to your server easily; but good news is there are some tricks which can resolve it, for instance, you can use jquery AjaxForm in your mvc form easily with a bit little modification. Take a look at jquery-ajax-form and its samples, you will get some good idea around it.
Normally you cannot upload files using AJAX. Modern browsers that support FormData would allow you to directly make AJAX requests containing multipart/form-data content. Also look at the native XMLHttpRequest object.
But if you need to support legacy browsers you will need some fallback mechanism such as hidden iframes or Flash movies. Plugins such as blueimp would detect the browser capabilities and upload the file using the best option that the browser supports.
I want to refactor an existing MVC action so that it can be used offline to build email content.
The action just fetches a model by Id and hands it over to the view, where the view renders it's fields. There is a foreach loop in the view.
My first thought was to just create an html file and do string search and replace in it.
Is there any template rendering libraries I should consider instead?
You may take a look at RazorEngine.
I want to render an MVC Page/View that will have varying widgets on the page. So some views might have Widget A, another page could have Widget A and B, etc. I was thinking each widget would be a partial view that I want to pass parameters. So if it was a weather widget, I would need to pass the partial view the Zip code etc.
My question is what the best way to approach this architecturally? We currently have an external xml file that stores this info: myview.xml (for myview.cshtm)
We don’t want to have an external file, but would like to store everything in one place maybe in the header of the view file itself? Any recommendations?
Independent widgets on your views?
Sounds like you just need to use RenderAction to render them.
More info by Haack
MSDN
I have a controller with an action:
SomeController/ActionToBePrinted
ActionToBePrinted() returns an html view.
This action is called from a normal mvc razor view when pressing a button - how would I go about sending the content of the view to a printer when the button is pressed?
Aloha,
Hugo
You cant send direct to the printer.
I suggest you to create a custom ActionResult, that returns a PDF file or something like that. ASP.NET MVC Action Results and PDF Content
You can show a html page as well and open the print dialog using javascript like this
Click to Print This Page
But always the user has to start the print process, you cant do this programmatically.
You can perform a GET request (e.g. use window.open() and pass in URL or use AJAX) and put the returned HTML contents into a new window. Then use
Window.print(). Then simply close the window when you are done.
You could tie this directly into a single view by adding something in the body, but I prefer to use JavaScript in these cases. This keeps the design acting as a re-useable object or service that can be used across multiple views. In other words, you setup the controller-model, but no view. Instead, JavaScript steps in as the View.
Keep in mind that HTML is not a print format. So if you need to control the layout, you should be using a print technology such as PDF. XSLT provides an excellent means to create both HTML and PDF output using the same data, albeit it's a lot more work to create XSLT templates than it is to slap down window.print
Personally, I have an MVC page acting as a service that takes URL parameters. The page hooks into Adobe XSL-FO and uses the params to drive the output.
Ok, so here is my situation. I am creating a web application using ASP.NET MVC 2 using the C# language. I have programmed in HTML, CSS, and PHP for several years and I am very new to ASP.NET. The part that I am having trouble with is the image gallery.
The setup: I have a link on the navigation bar that goes to a "Galleries" page. This page will show a list of galleries. Each gallery has a title, an image, and a description. All of this information is pulled from an XML file. I'm using the XML file like a database. I wanted to use this method so that i could easily update the list of galleries and have the updated XML file automatically be reflected by the website. Now, the galleries should link to an "Images" page. This page will display a list of images within the gallery based on what gallery was selected. This page will also pull from an XML file.
The problem: I cannot seem to attach a dynamic link to the image? I am also stuck and not sure how to get the correct View to display. I know I need to do something with the controllers and models, right? I have some code if needed? I would greatly appreciate any help or direction for this! Thanks!
For the image, as long as you have the collection of images in the Model for the page, you can loop through each element and do something like:
<a href="<%= Html.Encode(image.Url) %>" />
When it comes to the Views, there's some auto-magic that happens behind the scenes to map you Controller to the View.
Scott Guthrie has a good post on the inner workings of the ASP.NET MVC Framework and the different methods that it uses to go from your Controller to your Views:
ASP.NET MVC Framework (Part 1) - ScottGu's Blog
I would much rather create an Html Helper for that. That way you can write something more along the lines of this:
<%= Html.ImageLink("<url to image">) %>
Feels like a cleaner solution to me then having to write out an anchor tag. Either way will work, though.
For more info on writing custom Html Helpers:
http://www.asp.net/Learn/MVC/tutorial-09-cs.aspx