0

Hi all hope you can help.

I am primarily a windows developer (winforms and wpf/mvvm) and it's been 10 years since my last web application, so this is probably a daft question.

I have just redeveloped a customer satisfaction questionnaire and as I had to figure out this from scratch thought I would use MVC 3 and Razor.

The Questionnaire is a single page web site with a controller that looks something like this.

    Function Index(BrandName As String, CaseID As Integer, EventID As Integer) As ActionResult

        ViewData("Scores") = Scores

        Dim questionnaire As New Questionnaire

        questionnaire.CaseID = CaseID
        questionnaire.EventID = EventID
        questionnaire.BrandName = BrandName

        //Get Some specific branding from the database
        questionnaire.FullBrandName = "FullNameFromDatabaseTable"

        Return View(questionnaire)

    End Function


    Function Save(questionnaire As Questionnaire) As ActionResult

        If TryUpdateModel(questionnaire) Then
            SaveQuestionnaireToDatabase(questionnaire)
        Else
            Return RedirectToAction("Index")
        End If

        Return View()

    End Function

I have stripped out some database code and some stuff to get a signed image url as i don't think its relevant.

I am not sure I fully understand the magic that is happening between view and controller which is the real reason for my question.

This is going up into azure along with everything else, I am asking the question about session state because this will be load balanced accross two instances. No authentication is required to access the page as it can only be completed once.

Many Thanks

p.s I couldn't get vb style quotes to work so put in the c# one.

Roman
  • 19,581
  • 6
  • 68
  • 84
David Steele
  • 3,433
  • 21
  • 23
  • If it is already completed it will return a page stating that it has already been filled in. I have left some stuff out of the example as i didn't think it was relevant. – David Steele May 09 '11 at 18:50

2 Answers2

0

If you have any content that needs to be shared / accessed across instances, simply use the AppFabric Cache, which went live about two weeks ago. I provided a link in this SO answer. The nice thing is that you can use the cache provider with just a few lines of code to set up, then call Put() and Get() for serializable key/value pairs. When you set up the cache, you can also enable a custom asp.net session state provider with a simple web config change - the Azure portal will auto-generate the xml for you.

Community
  • 1
  • 1
David Makogon
  • 69,407
  • 21
  • 141
  • 189
  • Although this is useful, it doesn't look like he's doing anything that touches the session, so there's no concern about which server the post goes to. All the information to process the request is submitted with the form. – Roman May 09 '11 at 18:58
  • Thanks David. I understand that I can do this (I am using it in some azure hosted SOAP Services). What I dont really understand is whether or not I do need any shared state. If a user is served a view from the Index Action on one role, clicks submit and this is processed by the Save action on another role is all that data there. – David Steele May 09 '11 at 18:59
  • ROMANARMY - I suspect that you have given the answer. I am not explictly doing anything with session so if all the information is included in the form submission then my two actions are independant can therefore run on separate instances. – David Steele May 09 '11 at 19:02
  • Ah - misunderstood then. So let me rephrase: In the event you need to share some content across instances, and would like to cache that content (maybe using a cache-aside pattern), then AppFabric Cache is a great resource. – David Makogon May 09 '11 at 19:27
0

It doesn't look like you are doing anything that touches the session, so there's no concern about which server the post goes to. All the information to process the request is submitted with the form.

You can take a look here (specifically section titled Implementing Add New Product ) to remove some of the mystery of how form data is mapped back to server side information.

Roman
  • 19,581
  • 6
  • 68
  • 84
  • Thanks for all your help. Loving MVC3, the html view helpers are very cool and the controllers just work. I think part of the problem was that it was so easy to do I thought It couldn't be so simple and I must be missing something. This mvc page is about 1\4 of the code in the old version, and it's now multi-tenant and much neater. Thanks again – David Steele May 09 '11 at 19:28
  • @David Steele: To be fair I'm not really a fan of html helpers and feel that the approach the Spark view engine takes is better, but that's me. – Roman May 09 '11 at 19:39
  • I will check it out. As I said it's my first web page for years and it's a hell of a lot better than it was. – David Steele May 09 '11 at 19:54