views:

22

answers:

1

I have a situation that I can't seem to find any help on. I looked through many questions on here, but can't seem to find anybody that has asked (or answered) my specific question. Here it is:

Assume I have 2 categories:

  • Paper (id: 1)
  • Plastic (id: 2)

The user clicks on Paper, change the name to Plastic, and click 'Submit'.

Inside my controller I discover that there is a already a category named Plastic so I re-sends the page to the user with a friendly message.

The problem arises when the user decides to not change the value, and instead navigate away from the page. They do some other things and then click on Paper again to change it's name. Only this time they actually see the name Plastic in the textbox!?

I have this problem on all of my controllers when I reject invalid form data. How do I fix this problem?

+1  A: 

I just wanted to answer this question myself to indicate my question was answered by queen3 in a comment. I discovered that the value was coming back from my LinqToSql with the invalid value.

The way that I fixed the issue was by registering the Castle Windsor PerWebRequestLifestyleModule http module like so:

<httpModule>
 <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" />
 ...
</httpModule>

Then I went to each component and set the lifestyle to PerWebRequest like so:

<component 
    id="..."
    service="..."
    type="..."
    lifestyle="PerWebRequest">

    ...

  </component>

Thanks queen3!

Luc