I’m writing a CMS system to learn MVC and was wondering if it’s possible in MVC to get a partial view with a form to post to a controller without the URL changing. It would be similiar idea to a code behind in webforms.
Say I have a comment module (displayed in a partial view) and want to add a comment, I don’t want the URL to change. Currently it redirects to /Comment/Add.
I think this is possible with ajax? But was also looking for an option for situations were ajax isn’t possible.
Is there any when to do this or will the posting of a form always cause a redirect?
I’m not sure I understand the question correctly, but what about calling
return RedirectToAction("actionName", "controllerName");or similar (basically sending them back to the main post again) at the end of the action where you post your comment?And of course you could customise it so it doesn’t do this if you’re using Ajax.
e.g. this sort of thing
I’ve done this sort of thing in the past and it works.