3

I am working on a .net mvc web application that has a bunch of web parts on the homepage. I realize that a webpart is a .net forms terminology, but wasn't sure what to name those mini sections. So anyways, for now these sections are called when that page is rendered, but eventually I will plug in JQuery and call these sections using AJAX. These mini sections or widgets will need to keep state as the user navigates between the homepage and back. With .net forms, the page state info is kept in the viewstate, but with .net mvc, that is not available (thankfully).

So, is there a framework already created for such functionality for MVC? If not, what would be the best way to handle this situation? I was thinking to leverage the HttpContext object and store everything in there, but not sure if that object has any size limitations.

2
  • They're called "partial views". Commented Nov 1, 2010 at 14:49
  • 1
    I would try to avoid managing "state" in MVC, seeing as how that's what ASP.NET forms (ViewState) is for. Commented Nov 1, 2010 at 14:51

4 Answers 4

2

Just like with anything else in MVC you're going to need to store the state somewhere. As other users have pointed out, using Partial Views will reduce the complication of the design by allowing you to have controllers that handle just those small parts. They can then be responsible for saving/restoring/tracking the state or info for that part. (This could be using a database, in process memory, whatever.)

If you put the controls in the master page you can have the parts' implementation removed from your other logic so you don't need to worry about capturing and returning data related to those parts with the rest of your model meant for your view.

Having the parts separate like that will make it a lot easier to AJAXify them as well since they would already be operating independently of your view data even though they are rendered at the same time.

Sign up to request clarification or add additional context in comments.

Comments

1

I think you want to check out Partial Views.

Comments

0

You can use output caching or data caching, both supported by MVC 1.0/2.0.

2 Comments

I am not trying to cache data, but trying to store the state of each partial view. For example, if the user minimized one of the widgets, I would like the app to remember that the next time that user navigates to the homepage only for that session. I don't think caching would be wise for this scenario.
0

Not sure if you're after this but project Orchard has a notion of widgets: http://www.orchardproject.net/docs/Default.aspx?Page=widgets&NS=&AspxAutoDetectCookieSupport=1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.