How to save a view automatically in MVC - asp.net

We have some views for an mvc application.we want to give save functionality on a particular view which will caputre everything from that view and save it in a folder on server eithier in pdf or html file type.
Save functionality should be called when user clicks on button on view.How can we achieve this.
Thanks in Advance.

First your view must be linked to your data model.
To manage the sync between both either you use binding mechanism if your framework supports it or you implement a observer/observable pattern.
Next you have to write an event handler to respond to the save event triggered by the save button.
This event handler must call the save functionality.
To be more precise you should tell which language/framework you are using.

Related

ASP.Net Dynamic popup window

I have a C# web app that pulls a json object from a web service after a button click even. This object has HTML code saved in one of its properties. I need to popup a window to the user from this server side event that displays this HTML.
The event could also return a list of objects so I would need the ability to display the popups one after the other.
What is the best way this handle this issue?
I found the answer I was lookinf for here
http://www.htmlgoodies.com/beyond/javascript/javascript-dynamic-document-creation-in-new-windows.html

Persist form data values in single page application

I have 2 views in my SPA built up using durandal. I have a form (consider basic employee information form) in the first view. Also, I am having a button in the view called "upload" which routes to a different view to upload some documents. Once user finishes uploading, it redirects back to my first view and when it does, the first view reloads (renders) again loosing all my previously entered values. Same is the case when I press browser back button on my second view (the upload page).
Any solution on how I can persist data in this case ?
Thanks.
Posting code would make it a bit easier but I would think you'd need to maybe store what's entered in LocalStorage or something and then retrieve it later?
AmplifyJS can make this easier.

Making Ajax for Fileuploads in ASP.NET, while keeping track of files in Memory

I need to make a Asp.net control to upload multiple files that sends the files through Ajax.
This control could be used to store the files on a Folder or in the Database, the persistense is going to be decided by the Classes that will use my control, not the Control itself. So i need to achieve a level of flexibility here.
The uploaded files will be stored my Control Class like a List of Files, until the class using my control execute the "official post" which will consume and then finally release the class.
In a simple example a Form using my control would consume the List generated by all the uploads made through my control and upong Save, the form would read my list and persist it the way is best.
The problem here is the approach:
I can't use a updatePanel because it doesn't allow for fileinputs and (afaik) won't keep the state of purelly javascript generated input=files.
It's not possible to use the WebMethod property to send the data since it requires my Method to be static which makes it impossible to feed a in memory object using this method.
The other option would be to use handmade Ajax, which is not that difficult, but I'm not sure how Asp.net will behave, does it keep states between Ajax Calls? Can I access the same in memory object from different calls? will i have to keep track of viewstates or use sessions? is it viable to use sessions or the viewstate(!) to keep uploaded files?
Reforcing: The problem is NOT Uploading the files with ajax, I'm using blueimp.github.com/jQuery-File-Upload , the problem is keeping track of them in the serverside without persisting.
Example
Let me try to explain a little better:
0) I have a control, this control has a property that is a List of the files - List<files> FilesUploaded;
1) On each ajax upload , I add the coming File into the list FilesUploaded.Add(FileComingFromAjax)
2) My controls goes into a form (any form), and when I save the Form BtSave.Click(), the Form class will need to get the list of files and persist so: they access it like this AnyonesForm.MyControl.FilesUploaded. Notice that the files are in Memory and not in the disk or the database.
My doubt is, Will the files be kept after each request? namelly:
Will the method call through ajax, use the Same List?
When i submit the main form, Will the List be accessible by the form class with the files I just uploaded?
Well Actually , I was thinking asp.net would be able to keep the objects between ajax requests, but this is not the case.
I'm going to use sessions, I'm not afraid to add objects to sessions anymore , ASP.net, adding objects to a session variable
Combine jQuery and AJAX like so:
jQuery Ajax File Upload
How can I upload files asynchronously?
to achieve your result.

ASP.Net Load Data from another page

i am facing one problem..
I have a page which has some templates related to user..
User use this template to send email..
User can have option to save this template and then he can load the saved templates...
What i want is on click on "Load Template" link. a new page appears which will display all the saved templates for logged in user. this page can contain grid. on select i want to close this load template page. and pass the text data back to previous page. which will display this template into text field. so that user can use saved templates.
How to do this using Asp.Net
You can do this using JavaScript, assuming the template selection window is opened with a call to window.open(). When the template is selected you can communicate and invoke methods (such as passing back the selected template ID) with code similar to this:
window.opener.templateSelected(selectedTemplateID);
window.close();
Here is information about window.opener
I believe that this may be what you're looking for. It's pretty straight forward and is in C#. It is done in .Net as opposed to client side JS.

InfoPath Submit functionality

I need to save my InfoPath form regardless of whether the required fields have been entered when the user clicks on a button. Is there a way to turn off validation for the InfoPath form temporarily?
By save i assume that you mean that you want to save the xml data file locally rather than submit your form to a datastore (webservice, sharepoint etc)
In tools>form options you can enable "save/save as" on the form (i think this is on by default) it will complain that there are validation errors but still allow you to save.
There is also save via code-behind using which will not go through the validation routine but will require that the form is fully trusted as it needs access resources that Infopath forms are normally restriced from using.
VB.Net
Me.SaveAs("c:\temp\myfile.xml")
C#
this.SaveAs("c:\temp\myfile.xml");
Or as Chris suggested allow nulls as part of your data source.
In my form, I required a button ("Save As Draft") that would submit the form to a SharePoint library even when validation errors were present.
This code-behind function worked for me:
public void SaveAsDraftButton_Clicked(object sender, ClickedEventArgs e)
{
this.Errors.DeleteAll();
this.Submit();
}
I've done similar by including radio buttons on the form with the labels 'I have completed this form and am ready to submit' and 'I am not done with this form. Save it and finish later'. Each validation then look something like (validation OR saveOptions == 'complete'). The submits similarly use this field to decide what actions to take.
You will have to write your own validation code in the code behind file and have it validate when the user clicks the submit button or not when you just want to have the code.
Another approach is to have the fields allow null values and only validate when they have text in them. This method would not require custom code.

Resources