Refreshing Html.Action - asp.net-mvc-4

I have a partial view rendered with an Html.Action() that I want to refresh on a button click. I've tried AJAX requests, but the data I'm passing back and forth exceeds the maximum length for JSON.
The basic structure of the page looks like:
<html>
<head>
...
</head>
<body>
<div>
#Html.Action("DisplayBox")
</div>
<div>
<input type="button" id="RefreshButton" value="Refresh Box" />
</div>
</body>
</html>
The reason why I'm asking for a method other than an AJAX request is that the partial I'm rendering is a PDF object:
#model byte[]
#{
String base64EncodedPDF = System.Convert.ToBase64String(Model);
Layout = null;
}
<object data="data:application/pdf;base64,#base64EncodedPDF"
width="900" height="900" type="application/pdf"></object>
Thus, the data passed to the partial view for rendering is too big to put in an AJAX request. On button click, I want to be able to execute the controller action and have the results update the partial with new data. Is there any way of doing this?

You have to load the HTML with the link to the controller that generate the PDF or generate the file on the server side, host it and return the URL of this PDF, then, javascript can redirect user to that file.
I don't think that returning file trough AJAX is really not a good practice!

Related

Show image in vue from api

I like to display images in a content in vue. The content ist stored in the db.
I use vue-auth-image
If i put the code <img v-auth-image="api/media/1"> in to the template section, it works well.
But whit the following code, it doesn't work:
<div v-html="issue.body" >
</div>
The response from the ajax call is "body": "<img src='api/media/17'>",
How can i display the image in the content?

How to showConfirmationDialog window form Struts Action

Hi Experts,
I want to know if it is possible in Struts 1.x to display a
confirmation dialog from Struts Action. In more detail :
I have Action Form,Action Class and importList.jsp file. When i click
a button(on the main Jsp file) .. the current importList.jsp is
displayed by setting the properties of Action Form. In this jsp file i
have ok and cancel button. When i click OK button, on the basis of
some condition i want to show the confirmation dialog saying yes or
no, if the user clicks yes it will move forward, and on cancel.. it
will move to main jsp file(not to importList.jsp file)
Any ideas ....
You can use javascript to get this done. Instead of "Yes/No" dialog you will get "Ok/Cancel" dialog box. You will have to replace "importList url" and "main page url" with your actual urls.
This may not be syntactically accurate but it's a start.
<head>
<script type="text/javascript">
$(document).ready(function(){
$('input[type=submit]').click(function(){
var answer = confirm("You will be forwarded. ");
if(answer){
//your logic
document.location.href="importList url";
}else{
//your logic
document.location.href="main page url";
}
});
});
</script>
</head>
<body>
<input type="submit" value="Ok" />
</body>

Dont understand how views work in ASP.NET

I'm trying to understand ASP.NET MVC4.
Within HomeController I have code that seems to call a view ...
public ViewResult RsvpForm()
{
return View();
}
And here is the view....
#model PartyInvites.Models.GuestResponse
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>RsvpForm</title>
</head>
<body>
<div>
#using (Html.BeginForm()) {
#Html.ValidationSummary()
<p>Your name: #Html.TextBoxFor(x => x.Name) </p>
<p>Your email: #Html.TextBoxFor(x => x.Email)</p>
<input type="submit" value="Submit RSVP" />
}
</div>
</body>
</html>
What I dont understand is...
How come the view has access to data when I the call view with empty parameters?
And what this is for: #model PartyInvites.Models.GuestResponse
What is going on with x => x.Name. I believe this is an anonymous function, but I dont understand the need for it. And I do not see where x comes from (it doesnt appear in the code above. Is it a global or something?).
To help with answers, I have done lots of PHP and web stuff and I have grasped most of C# and Razor, so I am assuming I am just being thick or this is something special for ASP
Thanks.
x => x.Name is an anonymous function - it's never executed.
In fact, the Html helper casts it as an Expression<Func<TModel, TProperty>>. This is similar to anonymous functions in PHP or passing functions around in JavaScript (Well, Func is, Expression wraps that and allows access to the execution tree of the function - basically tons of metadata about the function itself).
Once in the html helper, TextBoxFor, there's a ton of extra processing and comparison of the expression tree against the model metadata. Attributes get factored in and all that is used to build up the HTML (like [Required] or [Scaffold])
Your controller doesn't pass in data, but the view declares a strong model.
In the view, #model PartyInvites.Models.GuestResponse does not mean any data is actually passed in. It merely declares the view as strongly typed and makes the model metadata available to Intellisense and the view compiler. The Controller/View relationship is a whole lot more complicated than just a simple function call, unlike most PHP MVC frameworks (or basic PHP includes). The data the controller passes in gets wrapped up into the Page and ViewData with all the metadata and controller context and more.

Web API controller POST attempts a file download on client

I've created an Web API controller in my MVC project. Whenever I try to POST to this controller, it try's to initiate a File download, and I am not sure why. It happens if I navigate to the API controller via URL or if it's done via a Form post.
It's a very simple scenario where an File is to be uploaded via a post.
Here is the controller code. Any ideas?
public class UploadController : ApiController
{
public async Task<List<string>> Post()
{
// Verify that this is an HTML Form file upload request
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
// Create a stream provider for setting up output streams that saves the output under c:\tmp\uploads
// If you want full control over how the stream is saved then derive from MultipartFormDataStreamProvider
// and override what you need.
MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider("c:\\tmp\\");
var task = await Request.Content.ReadAsMultipartAsync(streamProvider);
return new List<string>();
}
Here is the client code:
<!DOCTYPE HTML>
<html>
<head>
<title>HTML5 Multiple File Upload Sample</title>
</head>
<body>
<form action="http://localhost:8080/api/upload" enctype="multipart/form-data" method="POST">
What is your name?
<input name="submitter" size="40" type="text"><br>
What files are you uploading?
<input name="data" type=file multiple>
<br>
<input type="submit" />
</form>
</body>
</html>
I suspect that you are using Internet Explorer to test this example, aren't you? But this browser always prompts for download when the server sends JSON (yeah IE sucks like hell, we all know that, please use a real web browser when you are doing web development). Your controller action returns JSON that IE is incapable of displaying inline and it asks you to save it on the client. I don't know what else did you expect? Your controller action returns an empty array as JSON. You have an HTML form to upload a file and the result of this file upload is an empty JSON array that IE doesn't know how to handle.
If you use an HTML client form you probably wanna return HTML from this API controller action, right?

WinJS: How can I access page functions and variables from HTML?

I'm defining page with some vars and methods. Then I wanna use it in html markup (for example data-win-bind="textContent: myPage.variable). How can I access page variables in html markup?
In the JavaScript code behind your page, say default.js, you'd include your ViewModel for the data binding, something like:
(function(){
WinJS.Namespace.define("MyModel.myPage", {
variable : null
};
MyModel.myPage.variable = 'foo';
})();
Then in when the page is activated (in default.js), you'll need to initialize the bindings with a call like
WinJS.Binding.processAll(document.body, MyModel);
There's quite a bit more functionality available though, so this is just a simplistic one-way binding case that should get you started. For more info, check out the Quickstart: binding data and styles.
You have to use javascript here's the skeleton:
<html>
<head>
<script type="text/javascript">
//Code goes here
</script>
</head>
<body>
</body>
<html>