I am using localstorage to maintain the data at client side in MVC.
I need to read the localstorage data in MVC controller. Is this possible?
If it is, please give me the solution how to do it.
The server doesn't have access to the client browser which is where the local data is stored . You will need to send the data to the server using javascript.
If you can give us some more information then i can give you an example that would solve your problem.
What version of MVC are you using (MVC2/3/4, WEB API, etc)?
What is the reason you need this data visible to the server?
Do you want the controller to do something with this data before it returns a new view?
etc.
Related
Currently I'm working on a ASP.NET MVC webapp which implemented a user dashboard where the user can add various charts to display data. We're using AngularJS for the client side to send the requests for data to a WebAPI solution.
The WebAPI action that returns the data is implemented as async - however, in the action we're querying some rather big Sql Server DB and apply various filters that the clients sets.
In case the user has more charts (10+) and he's "hitting" a big data set the Action on the WebAPI can take a bit of time to process.
My issue is that in Firebug I see all the GET requests being sent by AngularJS to the WebAPI, some of them (2-3) start being processed immediately, but the rest seems to get queued and in Firebug once they are finally processed I see that the Connecting time for them is huge.
Can anyone give me any idea and make understand why WebAPI doesn't seem to respond to all the requests immediately? What am I missing? Are there any settings that I could apply to improve the performance on the WebAPI?
Thank you in advance for any suggestions!
Andrei
I am working on writing a web api for my application that is currently written using ASP.NET Web Forms. I have a module that acquires some data at the beginning of the request and stores it in HttpContext.Current.Items so that it is available to all code later during the page processing.
I am trying to write my web api and it needs to do the same thing. What is the correct way to store "per request" global data to be used during processing for a web api controller (I suspect it would be the same for a regular controller as well).
Also, if there is a way to do so, is there a way to set this data in an IHttpModule that runs prior to the controller being instantiated.
Any help is appreciated!
You can use the HttpRequestMessage.Properties dictionary as per this StackOverflow question.
There are other options like HttpContext or Session, but they can't be used in a self-hosting setup, only in WebHosting mode.
What is the best way to create forms (textfields, checkboxes, radio buttons, ...) and handle the data after the user's input?
Just use web components as dart's web ui?
http://www.dartlang.org/articles/web-ui/
http://www.dartlang.org/docs/tutorials/web-ui/
edit: Lets imagine the following example application: I would like to create an online quiz/test.
First the user has to register
Data will be stored in a textfile or in a database
User can log in and play an online quiz or do an online test.
For that quiz/test i need to evaluate the input with the predefined correct answers
Here's a high-level answer to your question.
To handle data on the server side you can use the HttpServer class to start a web server. See this article.
To store data in a flat file you'll need to use the dart:io package to open a file and write to it. See the documentation for File.openWrite().
To store data in a database there are packages available on pub for mysql and postgresql.
There are two different ways to implement the client side. The traditional way is to use templating to generate html with the data in input elements within a form tag, and then handle the form submission in your webserver.
The modern way, that is the focus within the Dart community, is to write a single page app, which uses HttpRequest to read data from and send data to the server (usually using json).
On the client side, you could retrieve data from server (e.g. as JSON) and use that to build a form. This seems like a good fit for a web component as elements can be dynamically added based on received data.
The component would be bound to the model so you can serialize the model object to JSON on submit and send it to server on submit or just send it as standard HTML form.
The server side of the story is less clear, there are no production quality web server libraries that I am aware of, but you could take a look at DartExpress as an example, or Stream, and there are others, more or less complete. Anyway, you would have to extract the POST payload from HttpRequest (if sent as JSON) or use the form data which is also accessible via queryParameters property - please note that this is Dart:io.HttpRequest class, not Dart:html.HttpRequest, and it is available only on server side.
The mentioned server frameworks simplify this part a bit.
Using Web-UI would be a good choice. The todomvc application illustrates nicely how to dynamically capture the input from a user. Processing on the server side is wide open as far as choices go. Dart does have server side capabilities, and you could use some of the existing libraries to accomplish what you want.
Another way that you can process the information server side is to comunicate with the DB directly using a REST based web service like CouchDB. Cloudant offers such a service and allows you to communicate directly to the DB from the client, providing you can overcome the Same-Origin-Policy. There are 2 ways to do this. Enable CORS on the CouchDB instance, or host your application on the server that has the DB, which is also possible with CouchDB.
Dart serverside also supports websockets, so you can easily deliver the user provided data to the server with web sockets, and then do whatever processing you like on the serverside.
One other option I can think of would be to have the information processed and saved in the local browser. You can access the local DB or local browser file system from the Dart client, and keep everything local. For statistics, you can have the client update a web service of your choice.
I am working on a project where I need to access external database (asp.net) for some content and display the content on Concrete5. How can I achieve this?
concrete5 uses the ADOdb php library. I'm assuming your asp.net application uses mssql.
http://phplens.com/lens/adodb/docs-adodb.htm#connect_ex
Scroll down a bit and you will get to the mssql part.
Are you asking how to connect to the database? Or how to take that data and display it on your concrete5 site?
Connecting to the database has nothing to do with concrete5 -- instead just google for "connect to SQL Server database from PHP" (or use ADODB as #mkly points out in his answer).
But if you are asking how to display the content, then the easiest way to do that is by creating a single_page -- see http://www.concrete5.org/documentation/developers/pages/single-pages
I am writing an iOS application that needs to access data from an external SQL Server 2005 database. I already have a website that accesses the same data.
I usually access the SQL server database using .NET along with stored procedures for security reasons.
I need to populate an array that will itself populate another TableViewController.
As I'm fairly new to the whole iOS thing, kindly let me know how I can do this. If it's possible, please suggest the syntax or Google keywords for this.
I'd recommend making a simple WCF .NET REST Service that queries your database and returns what you need.
I'm pretty sure your iOS app will not be able to connect to it directly.
Check out the following;
http://msdn.microsoft.com/en-us/library/bb412178.aspx
http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide
The code project tutorial is very easy to follow. And you can download the project code.
It sounds like you will want to make an API to access your database and you can access it through web requests. Essentially you will be performing web requests and respond from your site in json or xml where within your iOS client side code you can parse that and do what you need with it.