Update two partial views when any column gets updated - asp.net-mvc-4

I have a page in which there are two partial views, one to the left and the other to the right. I would like these two views to be refreshed automatically when the tables that they are related to gets updated. Is SignalR the best option? and Is it complicated to implement this to an existing project? Right now I am using javascript 'set interval' to update every few seconds. Instead of doing constant polling I want to update the views only when the data gets refreshed. I am new to SignalR.
This is a ASP.NET mvc project,I want to update these two views only when the information pertaining to this user gets updated.
Please advise!

SignalR is a better option when compared to requesting for update in a regular interval since SignalR solution gives you more instant updates on your UI.
In your case, you might have to send out broadcasts from the server as soon as you update the backend tables.
Is it complicated to implement this to an existing project?
That's upto the architecture of your project, however implementing it in an MVC application is not so hard.
Here is an example of how SignalR is implemented in an MVC project.

Related

Whats the best way to refresh the interface after I add a item data to database?

How to refresh the interface after you add a strip of data to the backend database in Vue.js?
I mean, if I add a item data to the database. there are two case for refresh the interface.
refresh the list api to get the page data.
append the added item data to local list.
what is the best way to do this?
I think both the solutions are valid it depends on what kind of write operation we are planning to do. Given that you do all the validations on the front-end which leaves lesser chance for errors on the backend. I do the following based on the use case.
Add/Update the item locally and then based on the response from the server I remove it again in case of an error. This is an optimistic technique used by a lot of websites and worls really well for CRUD kind of operations.
Let's say that your new operating is going to creaate a new user in a 3rd party api. So doing an optimistic thing might not be the best. So what I do is make the request, show a toast/alert that the request is happening, and then use sockets or long polling to get the changes. When the request is finally done show the data. In the meanwhile you can insert a dummy item showing loading.

Which plugin is used to show the data in front end of socrata

Is it possible to implement the view(the table) that socrata gives to users to implement in a mvc application? Especially the scroll effect where it takes only ms to load data.
If not can anyone suggest any lightweight grid for same (scroll with faster loading)
The scroll effect is making use of paging by loading data dynamically, rather than trying to load the entire dataset at once.
If you are using SODA.NET, the Resource object has a GetRows(limit, offset) method that you can use to retrieve paged sets of rows in the dataset.
There are any number of ways you could implement the scroll-to-load, including client-side AJAX requests. See this answer to a related question for a starting point.

Storing user specific data in ASP.NET MVC

In my application each user has it's own menus depending on changing information on the database.
This way when a user logs-in I have to keep the parameters he can choose somewhere in a Station state table.
So when he choose the parameters I'll retrieve the correspondent option id and make a response from there.
I'm keeping this value in a Current Session object but I'm encountering several problems.
What's the best practice for doing this?
I'm reading several articles that state the Session object is not a good idea in ASP.NET MVC.
Session objects can still be used within MVC check out the answer here Using Session objects in MVC, Is it really bad?
It points to 2 other questions that had a similar question.
What kind of problems are you having?
You can use Asp.Net Cookies, you can create, assign and destroy within the controller
Follow this link Cookies in ASP.Net MVC 5 for more help ...

ASP.NET MVC - check Facebook login status

This is more of a design question.
I figured out how to use the facebook login via the Facebook SDK c#.
QUESTION: What is the best way to check whether the user is logged into FB or not each time the user goes to a different page?
Back on ASP.NET webforms, I could simply put in code to check FB login status in the code behind of a master page. This was good ... once and done. But I don't understand how to implement something similar in Asp.Net MVC 4.0.
Given that the _Layout.cshtml file (which acts like a master page) is only a view (hence, no code behind), what is the best way to code a way to check if the user is logged into FB each time a user goes to a different web page? Because I would think, adding this bit of code to each controller can't be the optimal design solution.
The only solution that I can think of involves using Javascript on the client side to do a WebApi call ... I guess the script will be bundled with all the other scripts so that it runs on each page. But I was hoping to find a solution on the server side ...
I'm pretty new to MVC, learning things as I go along ... tips appreciated ... thanks!
I can think of a couple of points that might help you devise a solution.
You can put code in your _Layout, but I agree that you want to be careful about doing so. You could create a helper or partial view and have your _Layout call it so that it's executed for every action. Your helper/partial would need to execute the required logic and then return something. The problem that I have with this is it's a lot of overhead every request.
You could do an AJAX call after the page is loaded (as you suggested). This means that the page still loads quickly. The problem I have with this is that you're now dependant on Javascript. It's also potentially a little hacky(?)
What about storing the user's status (logged on/off) in a session/cookie and also providing a 5 minute expiry. You can use the Helper/Partial method from before or have some logic fire in OnActionExecuting (or similar). Your logic should check to see if the status has expired and then connect to the Facebook API to update the status. This has the advantage of low overhead (i.e. not checking again until 5 minutes has passed).
I don't know of your exact situation so I can't say what method, if any, is best.

Connecting Multiple Visual Web Parts and persisting the ViewModel

I currently have several web parts:
EmailValidation
PrimaryDetails
AdditionalDetails
These are currently all connected together using similar logic to this and share a common RegistrationViewModel.
The issue is I use an Interface that holds all the values for the registration process and need these to be persisted across the web parts. In version 1 of the registration process I used a set of hidden values to hold the bits of information in between posts. We were hoping to get away from this approach and wondered if you knew of a tidier way to maintain state of an interface throughout the page calls. The issue is that each web part only has a portion of the fields on the form.
The only thing I could think of would be to store it in session data but a colleague didn’t sound keen on this due to the additional setup for that on all the servers.
Is there a way of getting the connections to maintain state across all posts?
EDIT:
My issue with using hidden fields is simply that on all the web parts I need the 15+ fields so if you add or remove anything it makes maintenance a bit annoying.
Maybe you can put that information in a cookie.
The hidden field solution doesn't seem bad, what is the exact problem with that?
EDIT: based on the problem with the Hidden fields solution:
You can have a class with the structure and serialize it into one single hidden field. If you need to add anything you just change the class and it will be replicated to the whole system. This is something similar to how the ViewState is implemented.