Mori
Mori

Reputation: 2574

How do I submit a form within a partial view?

I am asking this question to make sure myself that I understood the subject.

"The only way to have a submit button inside a partial view is using Ajax techniques to submit the form"

Upvotes: 1

Views: 974

Answers (2)

McGarnagle
McGarnagle

Reputation: 102743

Well, technically you could do a normal postback from a partial view. But that would tend to defeat the point of a partial:

  1. the entire page would have to be re-loaded, which means the result of the partial-view postback would need to be a complete page.
  2. the partial view's modularity suffers, because the result of its postback falls out of the partial view's scope (ie, the partial view needs to know about the entire current page).

So, it's an irregular thing to do a non-AJAX postback from a partial view. But there are scenarios where it would be useful/appropriate. Consider for example a "login" partial: you may want to post the credentials back to a specific controller/action, and have that action redirect back to the current page. In that case you could reasonably use a non-AJAX form.

Upvotes: 3

Jonathan Wood
Jonathan Wood

Reputation: 67193

The only way to have a submit button inside a partial view is using Ajax techniques to submit the form

You didn't say where you got the quote from, but this isn't true.

You submit a form from a partial view in exactly the same way you submit a form within a main view. You can do this using custom fields or by making your partial view strongly typed. Where are you getting hung up?

Upvotes: 1

Related Questions