I'm currently using the ASP.NT MVC RC1 to implement a basic timesheet application. I'd like to follow the DRY principles but finding it difficult in one particular case:
One of my views, a partial view actually, has a number of textboxes that represent the number of hours spent on a particular task, one textbox per day of the week. When I initially load the page, I want a textbox in the view to display the total of all those hours. Additionally, I want that total to update as I change the values in the textboxes. The update to the textboxes does not cause a full postback, only an AJAX postback that does not do anything with the results (the postback updates the value on the DB but the return ActionResult is an EmptyResult as there is nothing I need to update on the UI).
Currently I have the controller create a view that is populated with the "total" for that view, so the logic that adds all the values is in the C# controller. On the UI side, I have javascript that updates the total on the UI level. But this isn't good because if I change the logic behind how that total is calculated, I have to change it in two places! AHH! NOT DRY!
So, how can I do this? The only answer that comes to me so far is to scrap the javascript code that calculates the total on the UI and instead have the AJAX postback return the new "total" for that view.
Are there other approaches?