0

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?

asked Dec 9, 2012 at 2:46

1 Answer 1

1

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.

answered Dec 9, 2012 at 15:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.