Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In an ASP.NET MVC project (Razor), I have a Get request, which loads two properties on a model, dependent on the property passed into the action method. So if the parameter has a value, the Group property is supplied data. But if not, the Groups collection property is supplied data.

In the post action method, when I process the data, to repopulate the view, I have to provide similar logic, and could getaway with returning Action(param) (the get response) to the caller.

My question is, based on experience, is that a good practice to get into? I see some downsides to doing that, but adds the lack of code redundancy. Or is there a better alternative?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Do you have to create the view from the POST? A nicer pattern might be to use Post/Redirect/Get; this way the data is POSTed to the action which simply returns a 302 redirect to the GET action with the appropriate parameters in the query string. The responsibility for rendering then remains with the GET whilst altering state on the server is kept within the 'POST'.

The additional benefit of doing this is that you solve the problem of user's making duplicate requests when refreshing the page.

In terms of Best Practice when working with the web, it might be worthwhile learning more about REST and trying to apply RESTful principles to your MVC application.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.